TS18004
No value exists in scope for the shorthand property 'age'. Either declare one or provide an initializer.
Broken Code ❌
export function getPerson() {
return {
age,
fistName: 'Benny',
lastName: 'Neugebauer',
};
}Fixed Code ✔️
If you want to use the shorthand property name syntax to access the age property, you have to make sure that this variable is defined in the first place:
export function getPerson() {
const age = 34;
return {
age,
fistName: 'Benny',
lastName: 'Neugebauer',
};
}Alternatively, you can avoid using the shorthand property name syntax:
export function getPerson() {
return {
age: 34,
fistName: 'Benny',
lastName: 'Neugebauer',
};
}