I tried to run the following code snippet but encountered an unexpected error:
interface Person {
firstName: string
}
const property: 'Name' = 'Name'
const zack: Person = {
[`first${property}`]: 'Zack'
}
An error is thrown when creating zack
:
Property 'firstName' is missing in type '{ [x: string]: string; }' but required in type 'Person'.
Further exploration revealed that any string concatenation seems to cause issues:
type EqualsFirstName = 'firstName'
const value: EqualsFirstName = 'first' + 'Name'
Unfortunately, that approach doesn't work either.