TS1036

error TS1036: Statements are not allowed in ambient contexts.

Bad 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;
}