TS18004

error TS18004: No value exists in scope for the shorthand property ‘age’. Either declare one or provide an initializer.

Bad Code ❌

1
2
3
4
5
6
7
export function getPerson() {
return {
age,
fistName: 'Benny',
lastName: 'Neugebauer'
}
}

Fixed Code ✔️

1
2
3
4
5
6
7
8
export function getPerson() {
const age = 34;
return {
age,
fistName: 'Benny',
lastName: 'Neugebauer',
};
}

Alternative:

1
2
3
4
5
6
7
export function getPerson() {
return {
age: 34,
fistName: 'Benny',
lastName: 'Neugebauer',
};
}