TS1036

error TS1036: Statements are not allowed in ambient contexts.

Broken Code ❌

1
2
3
4
5
import { APIClient } from "../../APIClient";

declare global {
client: APIClient;
}

Fixed Code ✔️

With declare global an ambient context is created. TypeScript does not allow statements in such ambient context declaration which is why we have to change the statement into a declaration:

1
2
3
declare global {
function client(): APIClient;
}

If you don’t want client to be a function, you have to use thevar` keyword:

1
2
3
declare global {
var client: APIClient;
}