Reputation: 18381
I am trying to generate a type using a value provided by a generic. Here is my attempt that doesn't compile
type modifyKey<T extends 'a' | 'b'> = {
[id: `${T}changed`]: T | string;
another: number
}
Upvotes: 0
Views: 38
Reputation: 33061
type modifyKey<T extends 'a' | 'b'> = {
[Prop in T as `${T}changed`]: T | string;
} & {
another: number
}
// type Result = { achanged: string; bchanged: string; another: number; }
type Result = modifyKey<'a' | 'b'>
Here you can find docs for property renaming
P.S. According to convention, type name should be capitalized
Upvotes: 2