Skip to content

Commit 03a98a2

Browse files
authored
Merge pull request #28783 from weswigham/fix-typeparam-parent
Add missing case to declaration diagnostic handler
2 parents 28f8fda + cd6fdb1 commit 03a98a2

6 files changed

+65
-0
lines changed

src/compiler/transformers/declarations/diagnostics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ namespace ts {
389389
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
390390
break;
391391

392+
case SyntaxKind.ConstructorType:
392393
case SyntaxKind.ConstructSignature:
393394
diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
394395
break;
@@ -410,6 +411,7 @@ namespace ts {
410411
}
411412
break;
412413

414+
case SyntaxKind.FunctionType:
413415
case SyntaxKind.FunctionDeclaration:
414416
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
415417
break;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tests/cases/compiler/declarationEmitLambdaWithMissingTypeParameterNoCrash.ts(2,27): error TS2304: Cannot find name 'T2'.
2+
tests/cases/compiler/declarationEmitLambdaWithMissingTypeParameterNoCrash.ts(2,27): error TS4016: Type parameter 'T1' of exported function has or is using private name 'T2'.
3+
tests/cases/compiler/declarationEmitLambdaWithMissingTypeParameterNoCrash.ts(3,33): error TS2304: Cannot find name 'T2'.
4+
tests/cases/compiler/declarationEmitLambdaWithMissingTypeParameterNoCrash.ts(3,33): error TS4006: Type parameter 'T1' of constructor signature from exported interface has or is using private name 'T2'.
5+
6+
7+
==== tests/cases/compiler/declarationEmitLambdaWithMissingTypeParameterNoCrash.ts (4 errors) ====
8+
export interface Foo {
9+
preFetch: <T1 extends T2> (c: T1) => void; // Type T2 is not defined
10+
~~
11+
!!! error TS2304: Cannot find name 'T2'.
12+
~~
13+
!!! error TS4016: Type parameter 'T1' of exported function has or is using private name 'T2'.
14+
preFetcher: new <T1 extends T2> (c: T1) => void; // Type T2 is not defined
15+
~~
16+
!!! error TS2304: Cannot find name 'T2'.
17+
~~
18+
!!! error TS4006: Type parameter 'T1' of constructor signature from exported interface has or is using private name 'T2'.
19+
}
20+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [declarationEmitLambdaWithMissingTypeParameterNoCrash.ts]
2+
export interface Foo {
3+
preFetch: <T1 extends T2> (c: T1) => void; // Type T2 is not defined
4+
preFetcher: new <T1 extends T2> (c: T1) => void; // Type T2 is not defined
5+
}
6+
7+
8+
//// [declarationEmitLambdaWithMissingTypeParameterNoCrash.js]
9+
"use strict";
10+
exports.__esModule = true;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/declarationEmitLambdaWithMissingTypeParameterNoCrash.ts ===
2+
export interface Foo {
3+
>Foo : Symbol(Foo, Decl(declarationEmitLambdaWithMissingTypeParameterNoCrash.ts, 0, 0))
4+
5+
preFetch: <T1 extends T2> (c: T1) => void; // Type T2 is not defined
6+
>preFetch : Symbol(Foo.preFetch, Decl(declarationEmitLambdaWithMissingTypeParameterNoCrash.ts, 0, 22))
7+
>T1 : Symbol(T1, Decl(declarationEmitLambdaWithMissingTypeParameterNoCrash.ts, 1, 15))
8+
>c : Symbol(c, Decl(declarationEmitLambdaWithMissingTypeParameterNoCrash.ts, 1, 31))
9+
>T1 : Symbol(T1, Decl(declarationEmitLambdaWithMissingTypeParameterNoCrash.ts, 1, 15))
10+
11+
preFetcher: new <T1 extends T2> (c: T1) => void; // Type T2 is not defined
12+
>preFetcher : Symbol(Foo.preFetcher, Decl(declarationEmitLambdaWithMissingTypeParameterNoCrash.ts, 1, 46))
13+
>T1 : Symbol(T1, Decl(declarationEmitLambdaWithMissingTypeParameterNoCrash.ts, 2, 21))
14+
>c : Symbol(c, Decl(declarationEmitLambdaWithMissingTypeParameterNoCrash.ts, 2, 37))
15+
>T1 : Symbol(T1, Decl(declarationEmitLambdaWithMissingTypeParameterNoCrash.ts, 2, 21))
16+
}
17+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/declarationEmitLambdaWithMissingTypeParameterNoCrash.ts ===
2+
export interface Foo {
3+
preFetch: <T1 extends T2> (c: T1) => void; // Type T2 is not defined
4+
>preFetch : <T1 extends any>(c: T1) => void
5+
>c : T1
6+
7+
preFetcher: new <T1 extends T2> (c: T1) => void; // Type T2 is not defined
8+
>preFetcher : new <T1 extends any>(c: T1) => void
9+
>c : T1
10+
}
11+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @declaration: true
2+
export interface Foo {
3+
preFetch: <T1 extends T2> (c: T1) => void; // Type T2 is not defined
4+
preFetcher: new <T1 extends T2> (c: T1) => void; // Type T2 is not defined
5+
}

0 commit comments

Comments
 (0)