-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add static index signature #37797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add static index signature #37797
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
ed1a798
Add static index
Kingwl f83b7de
fix lint
Kingwl d6fdab8
make lint happy
Kingwl 8eca2be
adjust test cases
Kingwl b7f614f
add more cases
Kingwl d4624e6
fix changes
Kingwl a13190a
Add more case
Kingwl 52884cc
accept baseline
Kingwl 5609985
fix error if extends others
Kingwl cf927fa
Update vfsUtil.ts
Kingwl 961f069
use equal to empty array
Kingwl 9ef7b85
Merge branch 'master' into static_index
Kingwl 830872e
static signature of interface is an error
Kingwl d74746d
Merge branch 'master' into static_index
Kingwl 0a8df61
Accept baseline
Kingwl 875cca3
Merge branch 'master' into static_index
Kingwl f327ed6
Check index constraints for static signature
Kingwl 0ff1549
Accpet baseline
Kingwl efeaf94
Fix crash
Kingwl 109e7c3
Merge branch 'master' into static_index
Kingwl 0ee41f6
fix crash
Kingwl f91d84b
Accept baseline
Kingwl aaf5185
Merge branch 'master' into static_index
Kingwl f8eddee
Merge branch 'master' into static_index
Kingwl 246585f
Fix regression
Kingwl 124e461
Fix crash
Kingwl 23cbc31
Merge branch 'master' into static_index
Kingwl f5508e1
always return new array
Kingwl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
6 changes: 3 additions & 3 deletions
6
tests/baselines/reference/parserIndexMemberDeclaration10.errors.txt
This file contains hidden or 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,4): error TS1071: 'static' modifier cannot appear on an index signature. | ||
tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,11): error TS1030: 'static' modifier already seen. | ||
|
||
|
||
==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (1 errors) ==== | ||
class C { | ||
static static [x: string]: string; | ||
~~~~~~ | ||
!!! error TS1071: 'static' modifier cannot appear on an index signature. | ||
~~~~~~ | ||
!!! error TS1030: 'static' modifier already seen. | ||
} |
9 changes: 0 additions & 9 deletions
9
tests/baselines/reference/parserIndexMemberDeclaration6.errors.txt
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts(2,5): error TS1071: 'static' modifier cannot appear on an index signature. | ||
tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts(2,13): error TS1023: An index signature parameter type must be either 'string' or 'number'. | ||
|
||
|
||
==== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer3.ts (1 errors) ==== | ||
class C { | ||
static [s: symbol]: string; | ||
~~~~~~ | ||
!!! error TS1071: 'static' modifier cannot appear on an index signature. | ||
~ | ||
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'. | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/staticIndexSignature1.errors.txt
This file contains hidden or 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,17 @@ | ||
tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts(10,1): error TS2322: Type '2' is not assignable to type '42'. | ||
|
||
|
||
==== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts (1 errors) ==== | ||
class C { | ||
static [s: string]: number; | ||
static [s: number]: 42 | ||
} | ||
|
||
C["foo"] = 1 | ||
C.bar = 2; | ||
const foo = C["foo"] | ||
C[42] = 42 | ||
C[2] = 2; | ||
~~~~ | ||
!!! error TS2322: Type '2' is not assignable to type '42'. | ||
const bar = C[42] |
This file contains hidden or 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 @@ | ||
//// [staticIndexSignature1.ts] | ||
class C { | ||
static [s: string]: number; | ||
static [s: number]: 42 | ||
} | ||
|
||
C["foo"] = 1 | ||
C.bar = 2; | ||
const foo = C["foo"] | ||
C[42] = 42 | ||
C[2] = 2; | ||
const bar = C[42] | ||
|
||
//// [staticIndexSignature1.js] | ||
var C = /** @class */ (function () { | ||
function C() { | ||
} | ||
return C; | ||
}()); | ||
C["foo"] = 1; | ||
C.bar = 2; | ||
var foo = C["foo"]; | ||
C[42] = 42; | ||
C[2] = 2; | ||
var bar = C[42]; |
This file contains hidden or 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,31 @@ | ||
=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts === | ||
class C { | ||
>C : Symbol(C, Decl(staticIndexSignature1.ts, 0, 0)) | ||
|
||
static [s: string]: number; | ||
>s : Symbol(s, Decl(staticIndexSignature1.ts, 1, 12)) | ||
|
||
static [s: number]: 42 | ||
>s : Symbol(s, Decl(staticIndexSignature1.ts, 2, 12)) | ||
} | ||
|
||
C["foo"] = 1 | ||
>C : Symbol(C, Decl(staticIndexSignature1.ts, 0, 0)) | ||
|
||
C.bar = 2; | ||
>C : Symbol(C, Decl(staticIndexSignature1.ts, 0, 0)) | ||
|
||
const foo = C["foo"] | ||
>foo : Symbol(foo, Decl(staticIndexSignature1.ts, 7, 5)) | ||
>C : Symbol(C, Decl(staticIndexSignature1.ts, 0, 0)) | ||
|
||
C[42] = 42 | ||
>C : Symbol(C, Decl(staticIndexSignature1.ts, 0, 0)) | ||
|
||
C[2] = 2; | ||
>C : Symbol(C, Decl(staticIndexSignature1.ts, 0, 0)) | ||
|
||
const bar = C[42] | ||
>bar : Symbol(bar, Decl(staticIndexSignature1.ts, 10, 5)) | ||
>C : Symbol(C, Decl(staticIndexSignature1.ts, 0, 0)) | ||
|
This file contains hidden or 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,51 @@ | ||
=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts === | ||
class C { | ||
>C : C | ||
|
||
static [s: string]: number; | ||
>s : string | ||
|
||
static [s: number]: 42 | ||
>s : number | ||
} | ||
|
||
C["foo"] = 1 | ||
>C["foo"] = 1 : 1 | ||
>C["foo"] : number | ||
>C : typeof C | ||
>"foo" : "foo" | ||
>1 : 1 | ||
|
||
C.bar = 2; | ||
>C.bar = 2 : 2 | ||
>C.bar : number | ||
>C : typeof C | ||
>bar : number | ||
>2 : 2 | ||
|
||
const foo = C["foo"] | ||
>foo : number | ||
>C["foo"] : number | ||
>C : typeof C | ||
>"foo" : "foo" | ||
|
||
C[42] = 42 | ||
>C[42] = 42 : 42 | ||
>C[42] : 42 | ||
>C : typeof C | ||
>42 : 42 | ||
>42 : 42 | ||
|
||
C[2] = 2; | ||
>C[2] = 2 : 2 | ||
>C[2] : 42 | ||
>C : typeof C | ||
>2 : 2 | ||
>2 : 2 | ||
|
||
const bar = C[42] | ||
>bar : 42 | ||
>C[42] : 42 | ||
>C : typeof C | ||
>42 : 42 | ||
|
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/staticIndexSignature2.errors.txt
This file contains hidden or 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,29 @@ | ||
tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(6,1): error TS2542: Index signature in type 'typeof C' only permits reading. | ||
tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(7,1): error TS2542: Index signature in type 'typeof C' only permits reading. | ||
tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(9,1): error TS2542: Index signature in type 'typeof C' only permits reading. | ||
tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(10,1): error TS2322: Type '2' is not assignable to type '42'. | ||
tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(10,1): error TS2542: Index signature in type 'typeof C' only permits reading. | ||
|
||
|
||
==== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts (5 errors) ==== | ||
class C { | ||
static readonly [s: string]: number; | ||
static readonly [s: number]: 42 | ||
} | ||
|
||
C["foo"] = 1 | ||
~~~~~~~~ | ||
!!! error TS2542: Index signature in type 'typeof C' only permits reading. | ||
C.bar = 2; | ||
~~~~~ | ||
!!! error TS2542: Index signature in type 'typeof C' only permits reading. | ||
const foo = C["foo"] | ||
C[42] = 42 | ||
~~~~~ | ||
!!! error TS2542: Index signature in type 'typeof C' only permits reading. | ||
C[2] = 2; | ||
~~~~ | ||
!!! error TS2322: Type '2' is not assignable to type '42'. | ||
~~~~ | ||
!!! error TS2542: Index signature in type 'typeof C' only permits reading. | ||
const bar = C[42] |
This file contains hidden or 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 @@ | ||
//// [staticIndexSignature2.ts] | ||
class C { | ||
static readonly [s: string]: number; | ||
static readonly [s: number]: 42 | ||
} | ||
|
||
C["foo"] = 1 | ||
C.bar = 2; | ||
const foo = C["foo"] | ||
C[42] = 42 | ||
C[2] = 2; | ||
const bar = C[42] | ||
|
||
//// [staticIndexSignature2.js] | ||
var C = /** @class */ (function () { | ||
function C() { | ||
} | ||
return C; | ||
}()); | ||
C["foo"] = 1; | ||
C.bar = 2; | ||
var foo = C["foo"]; | ||
C[42] = 42; | ||
C[2] = 2; | ||
var bar = C[42]; |
This file contains hidden or 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,31 @@ | ||
=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts === | ||
class C { | ||
>C : Symbol(C, Decl(staticIndexSignature2.ts, 0, 0)) | ||
|
||
static readonly [s: string]: number; | ||
>s : Symbol(s, Decl(staticIndexSignature2.ts, 1, 21)) | ||
|
||
static readonly [s: number]: 42 | ||
>s : Symbol(s, Decl(staticIndexSignature2.ts, 2, 21)) | ||
} | ||
|
||
C["foo"] = 1 | ||
>C : Symbol(C, Decl(staticIndexSignature2.ts, 0, 0)) | ||
|
||
C.bar = 2; | ||
>C : Symbol(C, Decl(staticIndexSignature2.ts, 0, 0)) | ||
|
||
const foo = C["foo"] | ||
>foo : Symbol(foo, Decl(staticIndexSignature2.ts, 7, 5)) | ||
>C : Symbol(C, Decl(staticIndexSignature2.ts, 0, 0)) | ||
|
||
C[42] = 42 | ||
>C : Symbol(C, Decl(staticIndexSignature2.ts, 0, 0)) | ||
|
||
C[2] = 2; | ||
>C : Symbol(C, Decl(staticIndexSignature2.ts, 0, 0)) | ||
|
||
const bar = C[42] | ||
>bar : Symbol(bar, Decl(staticIndexSignature2.ts, 10, 5)) | ||
>C : Symbol(C, Decl(staticIndexSignature2.ts, 0, 0)) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.