I have the following type:
type Test = {
roles: ["nonProfit"];
nonProfitPrivateDetails: NonProfitPrivateDetails;
} | {
roles: ["artist"];
artistPrivateDetails: ArtistPrivateDetails;
} | {
roles: ["artist", "nonProfit"];
nonProfitPrivateDetails: NonProfitPrivateDetails;
artistPrivateDetails: ArtistPrivateDetails;
}
However, when I try to use Array includes on it, the type isn't being inferred:
const t: Test = null as any
t.roles.includes("artist") // fails to compile.
It fails because "Argument of type 'string' is not assignable to parameter of type 'never'".
IntelliSence is showing includes as a type of: Array<T>.includes(searchElement: never, fromIndex: number | undefined): boolean.
I think I'm just going to have to write custom type guards instead of using includes, but I'd like to understand why this doesn't work.
Thanks!
rolesin a quantum superposition where it is every single type it can possibly be at once, and simply put, you are never guaranteed to get anything from that :D