[SOLVED] how can I declare a global variable in typescript

Table of Contents

Issue

I declare a global variable in typescript something like:
global.test = “something”
I try to do that I get the error property ‘test’ does not exist on type ‘Global’.

Solution

I try to do that I get the error property ‘test’ does not exist on type ‘Global’.

Create a file globals.d.ts with

interface Global {
 test: string;
}

More

Declaration files : https://basarat.gitbook.io/typescript/docs/types/ambient/d.ts.html

Answered By – basarat

Answer Checked By – Mildred Charles (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *