Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native "global" variable Intellij undefined

This is app.tsx

{global.HermesInternal == null ? null : (
    <View style={styles.engine}>
    <Text style={styles.footer}>Engine: Hermes</Text>
    </View>
)}

This is package.json

  "devDependencies": {
    "@babel/core": "^7.5.0",
    "@babel/runtime": "^7.5.0",
    "@react-native-community/eslint-config": "^0.0.3",
    "@types/jest": "^24.0.15",
    "@types/react": "^16.9.2",
    "@types/react-native": "^0.60.15",
    "@types/react-test-renderer": "^16.8.2",
    "babel-jest": "^24.1.0",
    "jest": "^24.1.0",
    "metro-react-native-babel-preset": "^0.54.1",
    "react-native-typescript-transformer": "^1.2.13",
    "react-test-renderer": "16.8.6",
    "typescript": "^3.6.3"
  },

I get a type error message from Intellij only "Unresolved variable of type global", but the app runs successfully. I tried adding @types/node and then a type error about HermesInternal not being part of global object is thrown.


Just for refernce in @types/react-native/index.d.ts this is the declaration:

declare global {
    ...
    const HermesInternal: null | {};
}
like image 693
Nikos Avatar asked Jul 12 '26 19:07

Nikos


1 Answers

I suspect this is a problem with the react native typings. As you've seen, the typings export a global HermesInternal object, but they don't declare the global parent object itself.

As a workaround, you can include this declaration above your component:

declare global {
  const global: { HermesInternal: null | {} }
}

Not ideal, but hopefully we will see an updated typings file to fix this issue. I'm currently on @types/[email protected].

like image 68
Chris Parton Avatar answered Jul 15 '26 07:07

Chris Parton