I have this type :
type FetcherEvents = {
signInWithEmailAndPassword: [email: string, password: string];
signUpWithEmailAndPassword: [email: string, password: string, ...data: any[]];
signWithEmail: [email: string, code: any];
}
And I want to convert each property to an object and creates an discriminated union.
So it becomes this :
type Resolved =
| {
type: "signInWithEmailAndPassword";
value: [email: string, password: string];
}
| {
type: "signUpWithEmailAndPassword";
value: [email: string, password: string, ...data: any[]];
}
| {
type: "signWithEmail";
value: [email: string, code: any];
};
Can you help me.
I find the solution :
First create an TuplifyUnion
To transform the union keyof 'some Type' into an Array (or tuple)
Don't ask me how TuplifyUnion is done, I copy it from another stackoverflow.
Second step you create ...Rest functions for Array and Objects.
Like this :
And the last step...
Your beautifull type to unionyse or eventyse (for xstate) your Interface :
So...
The the resolved type :
outputs:
Thanks you. TypeScript is the best...