TS2448

error TS2448: Block-scoped variable ‘add’ used before its declaration.

Broken Code ❌

Function expressions cannot be hoisted (used before they are declared):

1
2
3
4
5
add(1, 2);

const add = (a: number, b: number): number => {
return a + b;
};

Fixed Code ✔️

Turn your function expression into a function declaration (which can be hoisted):

1
2
3
4
5
add(1, 2);

function add(a: number, b: number): number {
return a + b;
}