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

How to type globalThis in React Native?

$
0
0

I'm trying to type globalThis but can't figure it out. I thought it was working in the past but now it doesn't.

// globalThis.app.tsimport { Platform } from 'react-native';globalThis.app = {  isIos: Platform.OS === 'ios',};// Freeze so these can only be defined in this file.Object.freeze(globalThis.app);
// typings/global.d.tsdeclare module globalThis {  const app: {    isIos: boolean;  };}

And at the top level...

// App.tsximport './globalThis.app';console.log(globalThis.app.isIos);

This logs to the console correctly and doesn't display a type error.
But, it also doesn't autocomplete and when I hover over .app it gives "any" as the type.

What is the correct way to type globalThis?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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