@@ -4753,15 +4753,15 @@ namespace ts {
4753
4753
getPropertiesOfObjectType(type);
4754
4754
}
4755
4755
4756
- function getConstraintOfTypeVariable (type: TypeVariable): Type {
4757
- return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>type) : getBaseConstraintOfTypeVariable (type);
4756
+ function getConstraintOfType (type: TypeVariable | UnionOrIntersectionType ): Type {
4757
+ return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>type) : getBaseConstraintOfType (type);
4758
4758
}
4759
4759
4760
4760
function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type {
4761
4761
return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : undefined;
4762
4762
}
4763
4763
4764
- function getBaseConstraintOfTypeVariable (type: TypeVariable): Type {
4764
+ function getBaseConstraintOfType (type: TypeVariable | UnionOrIntersectionType ): Type {
4765
4765
const constraint = getResolvedBaseConstraint(type);
4766
4766
return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined;
4767
4767
}
@@ -4775,15 +4775,15 @@ namespace ts {
4775
4775
* type variable has no constraint, and the circularConstraintType singleton is returned if the constraint
4776
4776
* circularly references the type variable.
4777
4777
*/
4778
- function getResolvedBaseConstraint(type: TypeVariable): Type {
4778
+ function getResolvedBaseConstraint(type: TypeVariable | UnionOrIntersectionType ): Type {
4779
4779
let typeStack: Type[];
4780
4780
let circular: boolean;
4781
- if (!type.resolvedApparentType ) {
4781
+ if (!type.resolvedBaseConstraint ) {
4782
4782
typeStack = [];
4783
4783
const constraint = getBaseConstraint(type);
4784
- type.resolvedApparentType = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type);
4784
+ type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type);
4785
4785
}
4786
- return type.resolvedApparentType ;
4786
+ return type.resolvedBaseConstraint ;
4787
4787
4788
4788
function getBaseConstraint(t: Type): Type {
4789
4789
if (contains(typeStack, t)) {
@@ -4834,7 +4834,7 @@ namespace ts {
4834
4834
* type itself. Note that the apparent type of a union type is the union type itself.
4835
4835
*/
4836
4836
function getApparentType(type: Type): Type {
4837
- const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfTypeVariable (<TypeVariable>type) || emptyObjectType : type;
4837
+ const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType (<TypeVariable>type) || emptyObjectType : type;
4838
4838
return t.flags & TypeFlags.StringLike ? globalStringType :
4839
4839
t.flags & TypeFlags.NumberLike ? globalNumberType :
4840
4840
t.flags & TypeFlags.BooleanLike ? globalBooleanType :
@@ -7427,14 +7427,12 @@ namespace ts {
7427
7427
return result;
7428
7428
}
7429
7429
}
7430
- // Given a type variable T with a constraint C, a type S is assignable to
7431
- // keyof T if S is assignable to keyof C.
7432
- if ((<IndexType>target).type.flags & TypeFlags.TypeVariable) {
7433
- const constraint = getConstraintOfTypeVariable(<TypeVariable>(<IndexType>target).type);
7434
- if (constraint) {
7435
- if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) {
7436
- return result;
7437
- }
7430
+ // A type S is assignable to keyof T if S is assignable to keyof C, where C is the
7431
+ // constraint of T.
7432
+ const constraint = getConstraintOfType((<IndexType>target).type);
7433
+ if (constraint) {
7434
+ if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) {
7435
+ return result;
7438
7436
}
7439
7437
}
7440
7438
}
@@ -7448,7 +7446,7 @@ namespace ts {
7448
7446
}
7449
7447
// A type S is related to a type T[K] if S is related to A[K], where K is string-like and
7450
7448
// A is the apparent type of S.
7451
- const constraint = getBaseConstraintOfTypeVariable (<IndexedAccessType>target);
7449
+ const constraint = getBaseConstraintOfType (<IndexedAccessType>target);
7452
7450
if (constraint) {
7453
7451
if (result = isRelatedTo(source, constraint, reportErrors)) {
7454
7452
errorInfo = saveErrorInfo;
@@ -7488,7 +7486,7 @@ namespace ts {
7488
7486
else if (source.flags & TypeFlags.IndexedAccess) {
7489
7487
// A type S[K] is related to a type T if A[K] is related to T, where K is string-like and
7490
7488
// A is the apparent type of S.
7491
- const constraint = getBaseConstraintOfTypeVariable (<IndexedAccessType>source);
7489
+ const constraint = getBaseConstraintOfType (<IndexedAccessType>source);
7492
7490
if (constraint) {
7493
7491
if (result = isRelatedTo(constraint, target, reportErrors)) {
7494
7492
errorInfo = saveErrorInfo;
@@ -15207,7 +15205,7 @@ namespace ts {
15207
15205
function isLiteralContextualType(contextualType: Type) {
15208
15206
if (contextualType) {
15209
15207
if (contextualType.flags & TypeFlags.TypeVariable) {
15210
- const constraint = getBaseConstraintOfTypeVariable (<TypeVariable>contextualType) || emptyObjectType;
15208
+ const constraint = getBaseConstraintOfType (<TypeVariable>contextualType) || emptyObjectType;
15211
15209
// If the type parameter is constrained to the base primitive type we're checking for,
15212
15210
// consider this a literal context. For example, given a type parameter 'T extends string',
15213
15211
// this causes us to infer string literal types for T.
0 commit comments