mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-07 18:25:51 -05:00
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:
55
tests/cases/compiler/indexedAccessWithFreshObjectLiteral.ts
Normal file
55
tests/cases/compiler/indexedAccessWithFreshObjectLiteral.ts
Normal 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]
|
||||
}
|
||||
Reference in New Issue
Block a user