0

I have a script which will run with a pre-defined binding, say response.

I have a TS interface which informs my code of what I can do with response.

How can I let TypeScript know that this pre-defined variable exists?

This is what I want to achieve:

import { HttpResponse } from './response';

// FIXME this binding already exists in the context of this script
let response: HttpResponse

// use response with type-checking
console.log(response.statusCode);

1 Answer 1

3

You can use global scope augmentation to make the code in the module aware that response is defined somewhere in the global scope:

import { HttpResponse } from './response';

declare global {
    let response: HttpResponse;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.