3 ms·
You can try this with typescript 4.1 : interface User { name: string; age: number; } type CapitalizeProperties<T> = { [Property in keyof T as Capita
by sbergot 6y ago
You can try this with typescript 4.1 :
interface User {
name: string;
age: number;
}
type CapitalizeProperties<T> = {
[Property in keyof T as Capitalize<string & Property>]: T[Property];
};
type CUser = CapitalizeProperties<User>;
var c : CUser = {
Age: 17,
Name: "john"
}
You can check that the autocompletion works on the c variable.
https://www.typescriptlang.org/play?ssl=1&ssc=1&pln=15&pc=2#code/JYOwLgpgTgZghgYwgAgKoGdrIN4ChkHIhwC2EAXMumFKAOYDc+hcdFRAriQEbRMC+uXGACeABxQBhOGOBg4AG2AAvCAAUoAewlQwwCOgA8AFQB8yALw5mAbQ3boo5KGQBrCCM0xkx5HHTI0rLySqqG1LQgdMgAZMj2OqKmALqUxnZaiSLJAkzC4lIYWFZBcooq6pmO+kZFUKZ5AG5wUMgIyJSSdZbWyACCbJQAjADsADT4AHKk7ABEAFaaABYgs7j8QA https://www.typescriptlang.org/play?ssl=1&ssc=1&pln=15&pc=2#...