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 } }; }
2.1m questions
2.1m answers
60 comments
56.9k users