TS2814

error TS2814: Function with bodies can only merge with classes that are ambient.

Solution

Bad Code ❌

1
2
3
4
5
class MyClass {
}

function MyClass(): void {
}

Your function cannot be named after your class, so you will have to rename your function:

Fixed Code ✔️

1
2
3
4
5
class MyClass {
}

function MyFunctionWithAnotherName(): void {
}

Alternatively you can declare an ambient class which gets implemented by your function:

1
2
3
4
5
declare class MyClass {
}

function MyClass(): void {
}