Take type A. Create type B by prefixing every key in A with x using Typescript's latest Template Literal Types:
type A = {
a: string;
b: string;
};
// Create this automatically.
type Prefixed = {
xa: string;
xb: string;
};
How do I do so?
type B = { [T in keyof typeof A as `x${T}`]: A[T] }
Some helpers like Capitalize<T> exist as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With