Merge pull request #23112 from Microsoft/fixTPReferenceLookups

Fix type parameter reference lookups
This commit is contained in:
Anders Hejlsberg
2018-04-03 12:32:05 -07:00
committed by GitHub
6 changed files with 159 additions and 1 deletions
+7 -1
View File
@@ -9108,6 +9108,11 @@ namespace ts {
return type;
}
function maybeTypeParameterReference(node: Node) {
return !(node.kind === SyntaxKind.QualifiedName ||
node.parent.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>node.parent).typeArguments && node === (<TypeReferenceNode>node.parent).typeName);
}
function isTypeParameterPossiblyReferenced(tp: TypeParameter, node: Node) {
// If the type parameter doesn't have exactly one declaration, if there are invening statement blocks
// between the node and the type parameter declaration, if the node contains actual references to the
@@ -9124,7 +9129,8 @@ namespace ts {
case SyntaxKind.ThisType:
return tp.isThisType;
case SyntaxKind.Identifier:
return !tp.isThisType && isPartOfTypeNode(node) && getTypeFromTypeNode(<TypeNode>node) === tp;
return !tp.isThisType && isPartOfTypeNode(node) && maybeTypeParameterReference(node) &&
getTypeFromTypeNode(<TypeNode>node) === tp;
case SyntaxKind.TypeQuery:
return true;
}
@@ -191,4 +191,15 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2
type C<T, V, E> =
{ [Q in { [P in keyof T]: T[P] extends V ? P : P; }[keyof T]]: C<T[Q], V, E>; };
// Repro from #23100
type A2<T, V, E> =
T extends object ? T extends any[] ? T : { [Q in keyof T]: A2<T[Q], V, E>; } : T;
type B2<T, V> =
T extends object ? T extends any[] ? T : { [Q in keyof T]: B2<T[Q], V>; } : T;
type C2<T, V, E> =
T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;
@@ -134,6 +134,17 @@ type B<T, V> =
type C<T, V, E> =
{ [Q in { [P in keyof T]: T[P] extends V ? P : P; }[keyof T]]: C<T[Q], V, E>; };
// Repro from #23100
type A2<T, V, E> =
T extends object ? T extends any[] ? T : { [Q in keyof T]: A2<T[Q], V, E>; } : T;
type B2<T, V> =
T extends object ? T extends any[] ? T : { [Q in keyof T]: B2<T[Q], V>; } : T;
type C2<T, V, E> =
T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;
//// [conditionalTypes2.js]
@@ -284,3 +295,12 @@ declare type C<T, V, E> = {
[P in keyof T]: T[P] extends V ? P : P;
}[keyof T]]: C<T[Q], V, E>;
};
declare type A2<T, V, E> = T extends object ? T extends any[] ? T : {
[Q in keyof T]: A2<T[Q], V, E>;
} : T;
declare type B2<T, V> = T extends object ? T extends any[] ? T : {
[Q in keyof T]: B2<T[Q], V>;
} : T;
declare type C2<T, V, E> = T extends object ? {
[Q in keyof T]: C2<T[Q], V, E>;
} : T;
@@ -496,3 +496,58 @@ type C<T, V, E> =
>V : Symbol(V, Decl(conditionalTypes2.ts, 133, 9))
>E : Symbol(E, Decl(conditionalTypes2.ts, 133, 12))
// Repro from #23100
type A2<T, V, E> =
>A2 : Symbol(A2, Decl(conditionalTypes2.ts, 134, 82))
>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8))
>V : Symbol(V, Decl(conditionalTypes2.ts, 138, 10))
>E : Symbol(E, Decl(conditionalTypes2.ts, 138, 13))
T extends object ? T extends any[] ? T : { [Q in keyof T]: A2<T[Q], V, E>; } : T;
>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8))
>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8))
>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8))
>Q : Symbol(Q, Decl(conditionalTypes2.ts, 139, 48))
>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8))
>A2 : Symbol(A2, Decl(conditionalTypes2.ts, 134, 82))
>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8))
>Q : Symbol(Q, Decl(conditionalTypes2.ts, 139, 48))
>V : Symbol(V, Decl(conditionalTypes2.ts, 138, 10))
>E : Symbol(E, Decl(conditionalTypes2.ts, 138, 13))
>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8))
type B2<T, V> =
>B2 : Symbol(B2, Decl(conditionalTypes2.ts, 139, 85))
>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8))
>V : Symbol(V, Decl(conditionalTypes2.ts, 141, 10))
T extends object ? T extends any[] ? T : { [Q in keyof T]: B2<T[Q], V>; } : T;
>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8))
>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8))
>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8))
>Q : Symbol(Q, Decl(conditionalTypes2.ts, 142, 48))
>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8))
>B2 : Symbol(B2, Decl(conditionalTypes2.ts, 139, 85))
>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8))
>Q : Symbol(Q, Decl(conditionalTypes2.ts, 142, 48))
>V : Symbol(V, Decl(conditionalTypes2.ts, 141, 10))
>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8))
type C2<T, V, E> =
>C2 : Symbol(C2, Decl(conditionalTypes2.ts, 142, 82))
>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8))
>V : Symbol(V, Decl(conditionalTypes2.ts, 144, 10))
>E : Symbol(E, Decl(conditionalTypes2.ts, 144, 13))
T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;
>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8))
>Q : Symbol(Q, Decl(conditionalTypes2.ts, 145, 26))
>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8))
>C2 : Symbol(C2, Decl(conditionalTypes2.ts, 142, 82))
>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8))
>Q : Symbol(Q, Decl(conditionalTypes2.ts, 145, 26))
>V : Symbol(V, Decl(conditionalTypes2.ts, 144, 10))
>E : Symbol(E, Decl(conditionalTypes2.ts, 144, 13))
>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8))
@@ -526,3 +526,58 @@ type C<T, V, E> =
>V : V
>E : E
// Repro from #23100
type A2<T, V, E> =
>A2 : A2<T, V, E>
>T : T
>V : V
>E : E
T extends object ? T extends any[] ? T : { [Q in keyof T]: A2<T[Q], V, E>; } : T;
>T : T
>T : T
>T : T
>Q : Q
>T : T
>A2 : A2<T, V, E>
>T : T
>Q : Q
>V : V
>E : E
>T : T
type B2<T, V> =
>B2 : B2<T, V>
>T : T
>V : V
T extends object ? T extends any[] ? T : { [Q in keyof T]: B2<T[Q], V>; } : T;
>T : T
>T : T
>T : T
>Q : Q
>T : T
>B2 : B2<T, V>
>T : T
>Q : Q
>V : V
>T : T
type C2<T, V, E> =
>C2 : C2<T, V, E>
>T : T
>V : V
>E : E
T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;
>T : T
>Q : Q
>T : T
>C2 : C2<T, V, E>
>T : T
>Q : Q
>V : V
>E : E
>T : T
@@ -136,3 +136,14 @@ type B<T, V> =
type C<T, V, E> =
{ [Q in { [P in keyof T]: T[P] extends V ? P : P; }[keyof T]]: C<T[Q], V, E>; };
// Repro from #23100
type A2<T, V, E> =
T extends object ? T extends any[] ? T : { [Q in keyof T]: A2<T[Q], V, E>; } : T;
type B2<T, V> =
T extends object ? T extends any[] ? T : { [Q in keyof T]: B2<T[Q], V>; } : T;
type C2<T, V, E> =
T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;