TypeScript/tests/baselines/reference/indexedAccessWithFreshObjectLiteral.errors.txt
okmttdhr 7db5f68144
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
2020-11-02 14:35:56 -08:00

64 lines
1.4 KiB
Plaintext

tests/cases/compiler/indexedAccessWithFreshObjectLiteral.ts(34,10): error TS2339: Property 'z' does not exist on type '{ a: number; b: string; c: boolean; }'.
==== tests/cases/compiler/indexedAccessWithFreshObjectLiteral.ts (1 errors) ====
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]
~~~~~~~
!!! error TS2339: Property 'z' does not exist on type '{ a: number; b: string; c: boolean; }'.
}
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]
}