Add index signature for anonymous object literal type (#37903)

* Use ts.map for stylistic consistency

* Show error only if noImplicitAny is set

* Accept baseline for noImplicitAnyIndexing

* Fix lint error

* Add test cases for indexedAccessWithFreshObjectLiteral
This commit is contained in:
okmttdhr
2020-11-03 07:35:56 +09:00
committed by GitHub
parent f646ec87fc
commit 7db5f68144
12 changed files with 608 additions and 32 deletions

View File

@@ -0,0 +1,55 @@
// @strict: true
function foo (id: string) {
return {
a: 1,
b: "",
c: true
}[id]
}
function bar (id: 'a' | 'b') {
return {
a: 1,
b: "",
c: false
}[id]
}
function baz (id: '1' | '2') {
return {
1: 1,
2: "",
3: false
}[id]
}
function qux (id: 1 | 2) {
return {
1: 1,
2: "",
3: false
}[id]
}
function quux (id: 'a' | 'b' | 'z') {
return {
a: 1,
b: "",
c: false
}[id]
}
function corge(id: string) {
return ({
a: 123,
b: ""
} as Record<string, number | string>)[id]
}
function grault(id: string) {
return ({
a: 123,
b: ""
} as { [k: string]: string | number})[id]
}