TS2322

error TS2322: Type ‘string’ is not assignable to type ‘number’.

Broken Code ❌

1
2
3
export function add(a: number, b: number): number {
return `${a + b}`;
}

Fixed Code ✔️

The type of the returned value must match the return type specified in the function signature:

1
2
3
export function add(a: number, b: number): number {
return parseInt(`${a + b}`, 10);
}

Video Tutorial