-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(25770): add diagnostic message for the possible mapped type used …
…as an index
- Loading branch information
1 parent
668bbc6
commit ee7fdf3
Showing
7 changed files
with
216 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tests/baselines/reference/typeUsedAsTypeLiteralIndex.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(8,5): error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(8,6): error TS2690: 'K2' only refers to a type, but is being used as a value here. Did you mean to use 'K in K2'? | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(11,6): error TS2300: Duplicate identifier 'K3'. | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(12,6): error TS2300: Duplicate identifier 'T3'. | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(13,5): error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(13,6): error TS2690: 'K3' only refers to a type, but is being used as a value here. Did you mean to use 'K in K3'? | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(16,6): error TS2300: Duplicate identifier 'K3'. | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(17,6): error TS2300: Duplicate identifier 'T3'. | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(18,5): error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts(18,6): error TS2693: 'K3' only refers to a type, but is being used as a value here. | ||
|
||
|
||
==== tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts (10 errors) ==== | ||
const K1 = Symbol(); | ||
type T1 = { | ||
[K1]: number; | ||
} | ||
|
||
type K2 = "x" | "y"; | ||
type T2 = { | ||
[K2]: number; | ||
~~~~ | ||
!!! error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~ | ||
!!! error TS2690: 'K2' only refers to a type, but is being used as a value here. Did you mean to use 'K in K2'? | ||
} | ||
|
||
type K3 = number | string; | ||
~~ | ||
!!! error TS2300: Duplicate identifier 'K3'. | ||
type T3 = { | ||
~~ | ||
!!! error TS2300: Duplicate identifier 'T3'. | ||
[K3]: number; | ||
~~~~ | ||
!!! error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~ | ||
!!! error TS2690: 'K3' only refers to a type, but is being used as a value here. Did you mean to use 'K in K3'? | ||
} | ||
|
||
type K3 = number | string; | ||
~~ | ||
!!! error TS2300: Duplicate identifier 'K3'. | ||
type T3 = { | ||
~~ | ||
!!! error TS2300: Duplicate identifier 'T3'. | ||
[K3]: number; | ||
~~~~ | ||
!!! error TS1170: A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~ | ||
!!! error TS2693: 'K3' only refers to a type, but is being used as a value here. | ||
k4: string; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//// [typeUsedAsTypeLiteralIndex.ts] | ||
const K1 = Symbol(); | ||
type T1 = { | ||
[K1]: number; | ||
} | ||
|
||
type K2 = "x" | "y"; | ||
type T2 = { | ||
[K2]: number; | ||
} | ||
|
||
type K3 = number | string; | ||
type T3 = { | ||
[K3]: number; | ||
} | ||
|
||
type K3 = number | string; | ||
type T3 = { | ||
[K3]: number; | ||
k4: string; | ||
} | ||
|
||
|
||
//// [typeUsedAsTypeLiteralIndex.js] | ||
const K1 = Symbol(); |
46 changes: 46 additions & 0 deletions
46
tests/baselines/reference/typeUsedAsTypeLiteralIndex.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
=== tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts === | ||
const K1 = Symbol(); | ||
>K1 : Symbol(K1, Decl(typeUsedAsTypeLiteralIndex.ts, 0, 5)) | ||
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --)) | ||
|
||
type T1 = { | ||
>T1 : Symbol(T1, Decl(typeUsedAsTypeLiteralIndex.ts, 0, 20)) | ||
|
||
[K1]: number; | ||
>[K1] : Symbol([K1], Decl(typeUsedAsTypeLiteralIndex.ts, 1, 11)) | ||
>K1 : Symbol(K1, Decl(typeUsedAsTypeLiteralIndex.ts, 0, 5)) | ||
} | ||
|
||
type K2 = "x" | "y"; | ||
>K2 : Symbol(K2, Decl(typeUsedAsTypeLiteralIndex.ts, 3, 1)) | ||
|
||
type T2 = { | ||
>T2 : Symbol(T2, Decl(typeUsedAsTypeLiteralIndex.ts, 5, 20)) | ||
|
||
[K2]: number; | ||
>[K2] : Symbol([K2], Decl(typeUsedAsTypeLiteralIndex.ts, 6, 11)) | ||
} | ||
|
||
type K3 = number | string; | ||
>K3 : Symbol(K3, Decl(typeUsedAsTypeLiteralIndex.ts, 8, 1)) | ||
|
||
type T3 = { | ||
>T3 : Symbol(T3, Decl(typeUsedAsTypeLiteralIndex.ts, 10, 26)) | ||
|
||
[K3]: number; | ||
>[K3] : Symbol([K3], Decl(typeUsedAsTypeLiteralIndex.ts, 11, 11)) | ||
} | ||
|
||
type K3 = number | string; | ||
>K3 : Symbol(K3, Decl(typeUsedAsTypeLiteralIndex.ts, 13, 1)) | ||
|
||
type T3 = { | ||
>T3 : Symbol(T3, Decl(typeUsedAsTypeLiteralIndex.ts, 15, 26)) | ||
|
||
[K3]: number; | ||
>[K3] : Symbol([K3], Decl(typeUsedAsTypeLiteralIndex.ts, 16, 11)) | ||
|
||
k4: string; | ||
>k4 : Symbol(k4, Decl(typeUsedAsTypeLiteralIndex.ts, 17, 17)) | ||
} | ||
|
50 changes: 50 additions & 0 deletions
50
tests/baselines/reference/typeUsedAsTypeLiteralIndex.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
=== tests/cases/compiler/typeUsedAsTypeLiteralIndex.ts === | ||
const K1 = Symbol(); | ||
>K1 : unique symbol | ||
>Symbol() : unique symbol | ||
>Symbol : SymbolConstructor | ||
|
||
type T1 = { | ||
>T1 : T1 | ||
|
||
[K1]: number; | ||
>[K1] : number | ||
>K1 : unique symbol | ||
} | ||
|
||
type K2 = "x" | "y"; | ||
>K2 : K2 | ||
|
||
type T2 = { | ||
>T2 : T2 | ||
|
||
[K2]: number; | ||
>[K2] : number | ||
>K2 : any | ||
} | ||
|
||
type K3 = number | string; | ||
>K3 : K3 | ||
|
||
type T3 = { | ||
>T3 : T3 | ||
|
||
[K3]: number; | ||
>[K3] : number | ||
>K3 : any | ||
} | ||
|
||
type K3 = number | string; | ||
>K3 : K3 | ||
|
||
type T3 = { | ||
>T3 : { k4: string; } | ||
|
||
[K3]: number; | ||
>[K3] : number | ||
>K3 : any | ||
|
||
k4: string; | ||
>k4 : string | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @target: esnext | ||
|
||
const K1 = Symbol(); | ||
type T1 = { | ||
[K1]: number; | ||
} | ||
|
||
type K2 = "x" | "y"; | ||
type T2 = { | ||
[K2]: number; | ||
} | ||
|
||
type K3 = number | string; | ||
type T3 = { | ||
[K3]: number; | ||
} | ||
|
||
type K3 = number | string; | ||
type T3 = { | ||
[K3]: number; | ||
k4: string; | ||
} |