Skip to content

Commit f99716d

Browse files
committed
Fix bug where generic type parameters weren't considered possibly type parameters.
1 parent c2b41ac commit f99716d

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9614,9 +9614,9 @@ namespace ts {
96149614
return type;
96159615
}
96169616

9617-
function maybeTypeParameterReference(node: Node) {
9617+
function maybeTypeParameterReference(node: Node, genericTypeParameter: boolean) {
96189618
return !(node.kind === SyntaxKind.QualifiedName ||
9619-
node.parent.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>node.parent).typeArguments && node === (<TypeReferenceNode>node.parent).typeName);
9619+
!genericTypeParameter && node.parent.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>node.parent).typeArguments && node === (<TypeReferenceNode>node.parent).typeName);
96209620
}
96219621

96229622
function isTypeParameterPossiblyReferenced(tp: TypeParameter, node: Node) {
@@ -9635,7 +9635,7 @@ namespace ts {
96359635
case SyntaxKind.ThisType:
96369636
return tp.isThisType;
96379637
case SyntaxKind.Identifier:
9638-
return !tp.isThisType && isPartOfTypeNode(node) && maybeTypeParameterReference(node) &&
9638+
return !tp.isThisType && isPartOfTypeNode(node) && maybeTypeParameterReference(node, !!tp.typeParameters) &&
96399639
getTypeFromTypeNode(<TypeNode>node) === tp;
96409640
case SyntaxKind.TypeQuery:
96419641
return true;

tests/baselines/reference/higherKindedTypesLift3.errors.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
tests/cases/compiler/higherKindedTypesLift3.ts(24,7): error TS2322: Type 'LC' is not assignable to type 'number[]'.
1+
tests/cases/compiler/higherKindedTypesLift3.ts(26,40): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'string[]'.
2+
Type 'number' is not assignable to type 'string'.
23

34

45
==== tests/cases/compiler/higherKindedTypesLift3.ts (1 errors) ====
@@ -26,9 +27,10 @@ tests/cases/compiler/higherKindedTypesLift3.ts(24,7): error TS2322: Type 'LC' is
2627

2728
const result = liftedStringLength(arrayOfStrings);
2829
const expectedType: Array<number> = result;
29-
~~~~~~~~~~~~
30-
!!! error TS2322: Type 'LC' is not assignable to type 'number[]'.
3130

3231
const expectError = liftedStringLength(result)
32+
~~~~~~
33+
!!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'string[]'.
34+
!!! error TS2345: Type 'number' is not assignable to type 'string'.
3335

3436

tests/baselines/reference/higherKindedTypesLift3.types

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ declare function stringLength(strarg: string): number
6565
>strarg : string
6666

6767
const liftedStringLength = liftedArray(stringLength);
68-
>liftedStringLength : (a: LC) => LC
69-
>liftedArray(stringLength) : (a: LC) => LC
68+
>liftedStringLength : (a: string[]) => number[]
69+
>liftedArray(stringLength) : (a: string[]) => number[]
7070
>liftedArray : LiftedResult<T[]>
7171
>stringLength : (strarg: string) => number
7272

@@ -75,20 +75,20 @@ declare const arrayOfStrings: Array<string>;
7575
>Array : T[]
7676

7777
const result = liftedStringLength(arrayOfStrings);
78-
>result : LC
79-
>liftedStringLength(arrayOfStrings) : LC
80-
>liftedStringLength : (a: LC) => LC
78+
>result : number[]
79+
>liftedStringLength(arrayOfStrings) : number[]
80+
>liftedStringLength : (a: string[]) => number[]
8181
>arrayOfStrings : string[]
8282

8383
const expectedType: Array<number> = result;
8484
>expectedType : number[]
8585
>Array : T[]
86-
>result : LC
86+
>result : number[]
8787

8888
const expectError = liftedStringLength(result)
89-
>expectError : LC
90-
>liftedStringLength(result) : LC
91-
>liftedStringLength : (a: LC) => LC
92-
>result : LC
89+
>expectError : number[]
90+
>liftedStringLength(result) : number[]
91+
>liftedStringLength : (a: string[]) => number[]
92+
>result : number[]
9393

9494

0 commit comments

Comments
 (0)