TS2454

error TS2454: Variable ‘myFavoriteNumber’ is used before being assigned.

Bad Code ❌

1
2
3
4
export function myNumber(): number {
let myFavoriteNumber: number;
return myFavoriteNumber;
}

Fixed Code ✔️

1
2
3
4
5
export function myNumber(): number {
let myFavoriteNumber: number;
myFavoriteNumber = 72;
return myFavoriteNumber;
}

or

1
2
3
4
export function myNumber(): number {
let myFavoriteNumber: number = 72;
return myFavoriteNumber;
}