TS2459

error TS2459: Module ‘./myFunction‘ declares ‘myFunction‘ locally, but it is not exported.

Broken Code ❌

myFunction.ts
1
2
3
4
5
function myFunction(a: number, b: number): number {
return a + b;
}

export {}
index.ts
1
2
3
import {myFunction} from './myFunction';

myFunction(1, 2);

Fixed Code ✔️

When you want to import your function in another file, you have to make sure that it is exported using the export keyword:

myFunction.ts
1
2
3
export function myFunction(a: number, b: number): number {
return a + b;
}
index.ts
1
2
3
import {myFunction} from './myFunction';

myFunction(1, 2);