Skip to content

Commit 67cdaf9

Browse files
Fixed crash when reporting infer extends on invalid name with declaration (#52032)
1 parent 94afa32 commit 67cdaf9

File tree

8 files changed

+42
-0
lines changed

8 files changed

+42
-0
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,6 +3864,10 @@
38643864
"category": "Error",
38653865
"code": 4084
38663866
},
3867+
"Extends clause for inferred type '{0}' has or is using private name '{1}'.": {
3868+
"category": "Error",
3869+
"code": 4085
3870+
},
38673871
"Conflicting definitions for '{0}' found at '{1}' and '{2}'. Consider installing a specific version of this library to resolve the conflict.": {
38683872
"category": "Error",
38693873
"code": 4090

src/compiler/transformers/declarations/diagnostics.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD
500500
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
501501
break;
502502

503+
case SyntaxKind.InferType:
504+
diagnosticMessage = Diagnostics.Extends_clause_for_inferred_type_0_has_or_is_using_private_name_1;
505+
break;
506+
503507
case SyntaxKind.TypeAliasDeclaration:
504508
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_type_alias_has_or_is_using_private_name_1;
505509
break;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts(1,42): error TS2304: Cannot find name 'B'.
2+
tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts(1,42): error TS4085: Extends clause for inferred type 'A' has or is using private name 'B'.
3+
4+
5+
==== tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts (2 errors) ====
6+
type Test<T> = T extends infer A extends B ? number : string;
7+
~
8+
!!! error TS2304: Cannot find name 'B'.
9+
~
10+
!!! error TS4085: Extends clause for inferred type 'A' has or is using private name 'B'.
11+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//// [inferTypesInvalidExtendsDeclaration.ts]
2+
type Test<T> = T extends infer A extends B ? number : string;
3+
4+
5+
//// [inferTypesInvalidExtendsDeclaration.js]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts ===
2+
type Test<T> = T extends infer A extends B ? number : string;
3+
>Test : Symbol(Test, Decl(inferTypesInvalidExtendsDeclaration.ts, 0, 0))
4+
>T : Symbol(T, Decl(inferTypesInvalidExtendsDeclaration.ts, 0, 10))
5+
>T : Symbol(T, Decl(inferTypesInvalidExtendsDeclaration.ts, 0, 10))
6+
>A : Symbol(A, Decl(inferTypesInvalidExtendsDeclaration.ts, 0, 30))
7+
>B : Symbol(B)
8+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts ===
2+
type Test<T> = T extends infer A extends B ? number : string;
3+
>Test : Test<T>
4+

tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ Info 32 [00:01:13.000] response:
12201220
"4082",
12211221
"4083",
12221222
"4084",
1223+
"4085",
12231224
"4090",
12241225
"4091",
12251226
"4092",
@@ -2553,6 +2554,7 @@ Info 38 [00:01:19.000] response:
25532554
"4082",
25542555
"4083",
25552556
"4084",
2557+
"4085",
25562558
"4090",
25572559
"4091",
25582560
"4092",
@@ -3798,6 +3800,7 @@ Info 40 [00:01:21.000] response:
37983800
"4082",
37993801
"4083",
38003802
"4084",
3803+
"4085",
38013804
"4090",
38023805
"4091",
38033806
"4092",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @declaration: true
2+
3+
type Test<T> = T extends infer A extends B ? number : string;

0 commit comments

Comments
 (0)