Open
Description
// No error. ✅
let okay = { id: 123, blah: "extra" } as { id: number };
// Errors. ❌
let waat = [{ id: 123, blah: "extra" }] as { id: number }[];
// ~~~~
// Conversion of type '{ id: number; blah: string; }[]' to type '{ id: number; }[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
// Type '{ id: number; blah: string; }' is not comparable to type '{ id: number; }'.
// Object literal may only specify known properties, and 'blah' does not exist in type '{ id: number; }'.
Expected: Both of these type assertions should consistently apply the appropriate relationship check, and both should be free of errors.
Actual: The first assertion is free of errors, while the second has an excess property error.
Similar example I found over at https://github.com/microsoft/TypeScript/pull/55152/files#r1275497478:
let okay = { foo: "" } as { id: 123 };
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
// Conversion of type '{ foo: string; }' to type '{ id: 123; }' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
// Property 'id' is missing in type '{ foo: string; }' but required in type '{ id: 123; }'.
let waat = [{ foo: "" }] as { id: 123 }[];
// ~~~
// Conversion of type '{ foo: string; }[]' to type '{ id: 123; }[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
// Type '{ foo: string; }' is not comparable to type '{ id: 123; }'.
// Object literal may only specify known properties, and 'foo' does not exist in type '{ id: 123; }'.