0 reply
0 recast
2 reactions
8 replies
1 recast
11 reactions
1 reply
0 recast
1 reaction
1 reply
0 recast
2 reactions
1 reply
0 recast
1 reaction
1 reply
0 recast
0 reaction
2 replies
0 recast
1 reaction
2 replies
0 recast
1 reaction
```ts
type Type = 'A' | 'B'
type From<
T extends Type = Type,
> = {
type: Type
A: T extends 'A' ? number : never
B: T extends 'B' ? string : never
}
type To<
T extends Type = Type,
> = {
type: Type
a?: T extends 'A' ? number : never
b?: T extends 'B' ? string : never
}
const transform = <
T extends Type = Type
>(
{ type, A, B }: From<T>,
): To<T> => ({
type,
...type === 'A' && {
a: A,
},
...type === 'B' && {
b: B,
},
})
``` 1 reply
0 recast
1 reaction
1 reply
0 recast
2 reactions