Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

how to set global variable in React Native in typescript?

$
0
0

I want to set a global variable in react native. It is neccessary and seems like only option in my particular usecase. I'm using typescript with my project. The problem is typescript complains when I set something like global.foo = bar; with the error "Property 'foo' does not exist on type 'typeof globalThis'." I have tried to create a declaration file like this -

declare module NodeJS {    export interface Global {        foo: any;    }}

and also with some other methods that I found online for react native or NodeJS. None seem to be working. Do anyone have any idea why this is not working. I have declared other modules in the same fashion and they all are working except the global one. Why?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>