4 ms·
That's great! Are you making the argument that I won't be able to find an example where doing some transform in a type-safe way is awkward in TypeScript, or jus
by dack 6y ago
That's great! Are you making the argument that I won't be able to find an example where doing some transform in a type-safe way is awkward in TypeScript, or just that this one example can be done in TypeScript?
By the way, my example was meant to be more like User -> User where there are some string values and some other types of value. You want to do the transformation in a generic way, but still have the type-safe object come out the other end with all the expected keys.
- deleted 6y ago[deleted]
- sbergot 6y agoYou 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#...
- deleted 6y ago[deleted]