Is there a way in typescript to set a property name from a variable?
Something like this
export function objectFactory(prop: string) { return { prop: { valid: false } }; }
You are looking for computed properties, this is an ES6 feature and not specific to TypeScript.
export function objectFactory(prop: string) { return { [prop]: { valid: false } }; }
1.4m articles
1.4m replys
5 comments
57.0k users