Open
Description
Example:
type ClientA = { firstName: string; lastName: string; isAdmin: boolean }
type ClientB = { fullName: string; isAdmin: boolean }
type ClientList = ClientA[] | ClientB[]
const list: ClientList = []
const admins = list.filter(c => c.isAdmin)
// ^^^^^^^^^^^^^^
// Error: Argument of type '<T>(c: T | undefined) => any' is not assignable to parameter of type 'BooleanConstructor'.
// Type '<T>(c: T | undefined) => any' provides no match for the signature 'new (value?: any): Boolean'
In this example both ClientA
and ClientB
has a common field isAdmin
but .filter()
can't handle this union.
Removing ts-reset
fixed the error.
Also changing the type to (ClientA | ClientB)[]
fixed the error, but it can be inconvenient in some cases because of a forced type cast.
Metadata
Metadata
Assignees
Labels
No labels