Type widening issue with `.filter(Boolean)`
Closed this issue · 5 comments
tjk commented
Is this expected?
type A = {
a: string
}
const as1: A[] = [
{ a: "1" },
{ a: "2", b: false },
// ^ Type '{ a: string; b: false; }' is not assignable to type 'A'.
// Object literal may only specify known properties, and 'b' does not exist in type 'A'.
]
const as2: A[] = [
{ a: "1" },
{ a: "2", b: false }, // no error
].filter(Boolean)
mattpocock commented
Doesn't look like ts-reset is to blame here!
tjk commented
@mattpocock could you elaborate please?
mattpocock commented
Try it without ts-reset installed - same result.
tjk commented
But without ts-reset, the base .filter(Boolean) improvements also have same
result.... I'm asking why this could not also be improved? We can both see
it could do a better job here, right? Is this just not possible?
…On Sun, Sep 3, 2023 at 1:01 AM Matt Pocock ***@***.***> wrote:
Try it without ts-reset installed - same result.
—
Reply to this email directly, view it on GitHub
<#163 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA2VKAOWO27OE5O6LQYEA3XYQ2NZANCNFSM6AAAAAA3ZI44V4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
mattpocock commented
Right - no, it isn't, because of the way that TS treats excess property checking.