16 lines
No EOL
1,000 B
Text
16 lines
No EOL
1,000 B
Text
tests/cases/compiler/arrayCast.ts(3,1): 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; }'.
|
|
Property 'id' is missing in type '{ foo: string; }'.
|
|
|
|
|
|
==== 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: Property 'id' is missing in type '{ foo: string; }'.
|
|
|
|
// Should succeed, as the {} element causes the type of the array to be {}[]
|
|
<{ id: number; }[]>[{ foo: "s" }, {}]; |