16 lines
No EOL
1.1 KiB
Text
16 lines
No EOL
1.1 KiB
Text
tests/cases/compiler/arrayCast.ts(3,23): error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other.
|
|
Type '{ foo: string; }' is not assignable to type '{ id: number; }'.
|
|
Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'.
|
|
|
|
|
|
==== tests/cases/compiler/arrayCast.ts (1 errors) ====
|
|
// Should fail. Even though the array is contextually typed with { id: number }[], it still
|
|
// has type { foo: string }[], which is not assignable to { id: number }[].
|
|
<{ id: number; }[]>[{ foo: "s" }];
|
|
~~~~~~~~
|
|
!!! error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other.
|
|
!!! error TS2352: Type '{ foo: string; }' is not assignable to type '{ id: number; }'.
|
|
!!! error TS2352: Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'.
|
|
|
|
// Should succeed, as the {} element causes the type of the array to be {}[]
|
|
<{ id: number; }[]>[{ foo: "s" }, {}]; |