Fixed crash when reporting infer extends on invalid name with declaration (#52032)

This commit is contained in:
Josh Goldberg 2023-01-10 16:11:24 -05:00 committed by GitHub
parent 94afa32925
commit 67cdaf9215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 0 deletions

View File

@ -3864,6 +3864,10 @@
"category": "Error",
"code": 4084
},
"Extends clause for inferred type '{0}' has or is using private name '{1}'.": {
"category": "Error",
"code": 4085
},
"Conflicting definitions for '{0}' found at '{1}' and '{2}'. Consider installing a specific version of this library to resolve the conflict.": {
"category": "Error",
"code": 4090

View File

@ -500,6 +500,10 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
break;
case SyntaxKind.InferType:
diagnosticMessage = Diagnostics.Extends_clause_for_inferred_type_0_has_or_is_using_private_name_1;
break;
case SyntaxKind.TypeAliasDeclaration:
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_type_alias_has_or_is_using_private_name_1;
break;

View File

@ -0,0 +1,11 @@
tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts(1,42): error TS2304: Cannot find name 'B'.
tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts(1,42): error TS4085: Extends clause for inferred type 'A' has or is using private name 'B'.
==== tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts (2 errors) ====
type Test<T> = T extends infer A extends B ? number : string;
~
!!! error TS2304: Cannot find name 'B'.
~
!!! error TS4085: Extends clause for inferred type 'A' has or is using private name 'B'.

View File

@ -0,0 +1,5 @@
//// [inferTypesInvalidExtendsDeclaration.ts]
type Test<T> = T extends infer A extends B ? number : string;
//// [inferTypesInvalidExtendsDeclaration.js]

View File

@ -0,0 +1,8 @@
=== tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts ===
type Test<T> = T extends infer A extends B ? number : string;
>Test : Symbol(Test, Decl(inferTypesInvalidExtendsDeclaration.ts, 0, 0))
>T : Symbol(T, Decl(inferTypesInvalidExtendsDeclaration.ts, 0, 10))
>T : Symbol(T, Decl(inferTypesInvalidExtendsDeclaration.ts, 0, 10))
>A : Symbol(A, Decl(inferTypesInvalidExtendsDeclaration.ts, 0, 30))
>B : Symbol(B)

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/types/conditional/inferTypesInvalidExtendsDeclaration.ts ===
type Test<T> = T extends infer A extends B ? number : string;
>Test : Test<T>

View File

@ -1220,6 +1220,7 @@ Info 32 [00:01:13.000] response:
"4082",
"4083",
"4084",
"4085",
"4090",
"4091",
"4092",
@ -2553,6 +2554,7 @@ Info 38 [00:01:19.000] response:
"4082",
"4083",
"4084",
"4085",
"4090",
"4091",
"4092",
@ -3798,6 +3800,7 @@ Info 40 [00:01:21.000] response:
"4082",
"4083",
"4084",
"4085",
"4090",
"4091",
"4092",

View File

@ -0,0 +1,3 @@
// @declaration: true
type Test<T> = T extends infer A extends B ? number : string;