mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
18 lines
716 B
TypeScript
18 lines
716 B
TypeScript
//// [tests/cases/compiler/arrayCast.ts] ////
|
|
|
|
//// [arrayCast.ts]
|
|
// 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" }];
|
|
|
|
// Should succeed, as the {} element causes the type of the array to be {}[]
|
|
<{ id: number; }[]>[{ foo: "s" }, {}];
|
|
|
|
//// [arrayCast.js]
|
|
"use strict";
|
|
// 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 }[].
|
|
[{ foo: "s" }];
|
|
// Should succeed, as the {} element causes the type of the array to be {}[]
|
|
[{ foo: "s" }, {}];
|