I am looking to create all possible configurations based on a given type.
type MagicGenerator<'withWishlist' | 'withAddToCart', PickerProps> = ??
Thus, the expected output of MagicGenerator
should look like this:
type ExpectedResult =
| ({
withWishlist: true;
withAddToCart: true;
} & PickerProps)
| ({
withWishlist?: false;
withAddToCart: true;
} & PickerProps)
| ({
withWishlist: true;
withAddToCart?: false;
} & PickerProps)
| ({
withWishlist?: false;
withAddToCart?: false;
} & { [P in keyof PickerProps]?: never });
The crux of the matter is that I want PickerProps
to default to never
only when both withWishlist
and withAddToCart
are either false or not provided
I attempted to implement something along these lines
type MagicGenerator<Keys extends string, Props extends object> =
| ({ [K in Keys]: true } & Props)
| ({ [K in Keys]?: false; } & {[P in Props]?: never})
but it did not yield the desired outcome
type NotFullResult = {
withWishlist: true;
withAddToCart: true;
pickerProp: any
} | {
withWishlist?: false | undefined;
withAddToCart?: false | undefined;
pickerProp?: undefined
}