@@ -4278,7 +4278,7 @@ namespace ts {
4278
4278
return createConditionalTypeNode(checkTypeNode, extendsTypeNode, trueTypeNode, falseTypeNode);
4279
4279
}
4280
4280
if (type.flags & TypeFlags.Substitution) {
4281
- return typeToTypeNodeHelper((<SubstitutionType>type).typeVariable , context);
4281
+ return typeToTypeNodeHelper((<SubstitutionType>type).baseType , context);
4282
4282
}
4283
4283
4284
4284
return Debug.fail("Should be unreachable.");
@@ -11327,9 +11327,7 @@ namespace ts {
11327
11327
// Get type from reference to named type that cannot be generic (enum or type parameter)
11328
11328
const res = tryGetDeclaredTypeOfSymbol(symbol);
11329
11329
if (res) {
11330
- return checkNoTypeArguments(node, symbol) ?
11331
- res.flags & TypeFlags.TypeParameter ? getConstrainedTypeVariable(<TypeParameter>res, node) : getRegularTypeOfLiteralType(res) :
11332
- errorType;
11330
+ return checkNoTypeArguments(node, symbol) ? getRegularTypeOfLiteralType(res) : errorType;
11333
11331
}
11334
11332
if (symbol.flags & SymbolFlags.Value && isJSDocTypeReference(node)) {
11335
11333
const jsdocType = getTypeFromJSDocValueReference(node, symbol);
@@ -11377,17 +11375,17 @@ namespace ts {
11377
11375
return links.resolvedJSDocType;
11378
11376
}
11379
11377
11380
- function getSubstitutionType(typeVariable: TypeVariable , substitute: Type) {
11381
- if (substitute.flags & TypeFlags.AnyOrUnknown || substitute === typeVariable ) {
11382
- return typeVariable ;
11378
+ function getSubstitutionType(baseType: Type , substitute: Type) {
11379
+ if (substitute.flags & TypeFlags.AnyOrUnknown || substitute === baseType ) {
11380
+ return baseType ;
11383
11381
}
11384
- const id = `${getTypeId(typeVariable )}>${getTypeId(substitute)}`;
11382
+ const id = `${getTypeId(baseType )}>${getTypeId(substitute)}`;
11385
11383
const cached = substitutionTypes.get(id);
11386
11384
if (cached) {
11387
11385
return cached;
11388
11386
}
11389
11387
const result = <SubstitutionType>createType(TypeFlags.Substitution);
11390
- result.typeVariable = typeVariable ;
11388
+ result.baseType = baseType ;
11391
11389
result.substitute = substitute;
11392
11390
substitutionTypes.set(id, result);
11393
11391
return result;
@@ -11397,25 +11395,25 @@ namespace ts {
11397
11395
return node.kind === SyntaxKind.TupleType && (<TupleTypeNode>node).elementTypes.length === 1;
11398
11396
}
11399
11397
11400
- function getImpliedConstraint(typeVariable: TypeVariable , checkNode: TypeNode, extendsNode: TypeNode): Type | undefined {
11401
- return isUnaryTupleTypeNode(checkNode) && isUnaryTupleTypeNode(extendsNode) ? getImpliedConstraint(typeVariable , (<TupleTypeNode>checkNode).elementTypes[0], (<TupleTypeNode>extendsNode).elementTypes[0]) :
11402
- getActualTypeVariable(getTypeFromTypeNode(checkNode)) === typeVariable ? getTypeFromTypeNode(extendsNode) :
11398
+ function getImpliedConstraint(type: Type , checkNode: TypeNode, extendsNode: TypeNode): Type | undefined {
11399
+ return isUnaryTupleTypeNode(checkNode) && isUnaryTupleTypeNode(extendsNode) ? getImpliedConstraint(type , (<TupleTypeNode>checkNode).elementTypes[0], (<TupleTypeNode>extendsNode).elementTypes[0]) :
11400
+ getActualTypeVariable(getTypeFromTypeNode(checkNode)) === type ? getTypeFromTypeNode(extendsNode) :
11403
11401
undefined;
11404
11402
}
11405
11403
11406
- function getConstrainedTypeVariable(typeVariable: TypeVariable , node: Node) {
11404
+ function getConditionalFlowTypeOfType(type: Type , node: Node) {
11407
11405
let constraints: Type[] | undefined;
11408
11406
while (node && !isStatement(node) && node.kind !== SyntaxKind.JSDocComment) {
11409
11407
const parent = node.parent;
11410
11408
if (parent.kind === SyntaxKind.ConditionalType && node === (<ConditionalTypeNode>parent).trueType) {
11411
- const constraint = getImpliedConstraint(typeVariable , (<ConditionalTypeNode>parent).checkType, (<ConditionalTypeNode>parent).extendsType);
11409
+ const constraint = getImpliedConstraint(type , (<ConditionalTypeNode>parent).checkType, (<ConditionalTypeNode>parent).extendsType);
11412
11410
if (constraint) {
11413
11411
constraints = append(constraints, constraint);
11414
11412
}
11415
11413
}
11416
11414
node = parent;
11417
11415
}
11418
- return constraints ? getSubstitutionType(typeVariable , getIntersectionType(append(constraints, typeVariable ))) : typeVariable ;
11416
+ return constraints ? getSubstitutionType(type , getIntersectionType(append(constraints, type ))) : type ;
11419
11417
}
11420
11418
11421
11419
function isJSDocTypeReference(node: Node): node is TypeReferenceNode {
@@ -12858,7 +12856,7 @@ namespace ts {
12858
12856
links.resolvedType = resolved.flags & TypeFlags.IndexedAccess &&
12859
12857
(<IndexedAccessType>resolved).objectType === objectType &&
12860
12858
(<IndexedAccessType>resolved).indexType === indexType ?
12861
- getConstrainedTypeVariable(<IndexedAccessType> resolved, node) : resolved;
12859
+ getConditionalFlowTypeOfType( resolved, node) : resolved;
12862
12860
}
12863
12861
return links.resolvedType;
12864
12862
}
@@ -12880,7 +12878,7 @@ namespace ts {
12880
12878
12881
12879
function getActualTypeVariable(type: Type): Type {
12882
12880
if (type.flags & TypeFlags.Substitution) {
12883
- return (<SubstitutionType>type).typeVariable ;
12881
+ return (<SubstitutionType>type).baseType ;
12884
12882
}
12885
12883
if (type.flags & TypeFlags.IndexedAccess && (
12886
12884
(<IndexedAccessType>type).objectType.flags & TypeFlags.Substitution ||
@@ -13428,6 +13426,10 @@ namespace ts {
13428
13426
}
13429
13427
13430
13428
function getTypeFromTypeNode(node: TypeNode): Type {
13429
+ return getConditionalFlowTypeOfType(getTypeFromTypeNodeWorker(node), node);
13430
+ }
13431
+
13432
+ function getTypeFromTypeNodeWorker(node: TypeNode): Type {
13431
13433
switch (node.kind) {
13432
13434
case SyntaxKind.AnyKeyword:
13433
13435
case SyntaxKind.JSDocAllType:
@@ -13775,7 +13777,7 @@ namespace ts {
13775
13777
return !!tp.isThisType;
13776
13778
case SyntaxKind.Identifier:
13777
13779
return !tp.isThisType && isPartOfTypeNode(node) && maybeTypeParameterReference(node) &&
13778
- getTypeFromTypeNode (<TypeNode>node) === tp;
13780
+ getTypeFromTypeNodeWorker (<TypeNode>node) === tp; // use worker because we're looking for === equality
13779
13781
case SyntaxKind.TypeQuery:
13780
13782
return true;
13781
13783
}
@@ -13976,7 +13978,7 @@ namespace ts {
13976
13978
return getConditionalTypeInstantiation(<ConditionalType>type, combineTypeMappers((<ConditionalType>type).mapper, mapper));
13977
13979
}
13978
13980
if (flags & TypeFlags.Substitution) {
13979
- const maybeVariable = instantiateType((<SubstitutionType>type).typeVariable , mapper);
13981
+ const maybeVariable = instantiateType((<SubstitutionType>type).baseType , mapper);
13980
13982
if (maybeVariable.flags & TypeFlags.TypeVariable) {
13981
13983
return getSubstitutionType(maybeVariable as TypeVariable, instantiateType((<SubstitutionType>type).substitute, mapper));
13982
13984
}
@@ -14985,7 +14987,7 @@ namespace ts {
14985
14987
const t = isFreshLiteralType(type) ? (<FreshableType>type).regularType :
14986
14988
getObjectFlags(type) & ObjectFlags.Reference && (<TypeReference>type).node ? createTypeReference((<TypeReference>type).target, getTypeArguments(<TypeReference>type)) :
14987
14989
type.flags & TypeFlags.UnionOrIntersection ? getReducedType(type) :
14988
- type.flags & TypeFlags.Substitution ? writing ? (<SubstitutionType>type).typeVariable : (<SubstitutionType>type).substitute :
14990
+ type.flags & TypeFlags.Substitution ? writing ? (<SubstitutionType>type).baseType : (<SubstitutionType>type).substitute :
14989
14991
type.flags & TypeFlags.Simplifiable ? getSimplifiedType(type, writing) :
14990
14992
type;
14991
14993
if (t === type) break;
0 commit comments