I am using the following type and have found it useful:
type MemberOfUnion<Union, Member> = Union extends Member | infer Inferred
? Inferred extends Union
? false
: true
: true;
type Test1 = MemberOfUnion<undefined | string, undefined>; // Result: true
type Test2 = MemberOfUnion<string | number, undefined>; // Result: false
type Test3 = MemberOfUnion<undefined, undefined>; // Result: true
type Test4 = MemberOfUnion<string, undefined>; // Result: false
type Test5 = MemberOfUnion<number, undefined>; // Result: false
type Test6 = MemberOfUnion<null | undefined, undefined>; // Result: true
type Test7 = MemberOfUnion<null, undefined>; // Result: false
type Test8 = MemberOfUnion<boolean | undefined, undefined>; // Result: true
type Test9 = MemberOfUnion<boolean, undefined>; // Result: false
type Test10 = MemberOfUnion<object | undefined, undefined>; // Result: true
type Test11 = MemberOfUnion<object, undefined>; // Result: false
type Test12 = MemberOfUnion<unknown | undefined, undefined>; // Result: false
type Test13 = MemberOfUnion<unknown, undefined>; // Result: false
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too