th3rdwave / react-native-safe-area-context

A flexible way to handle safe area insets in JS. Also works on Android and Web!
MIT License
2.14k stars 197 forks source link

Typescript v5: error TS4111: Property 'NODE_ENV' comes from an index signature, so it must be accessed with ['NODE_ENV']. #409

Closed patlux closed 1 year ago

patlux commented 1 year ago

../../node_modules/react-native-safe-area-context/src/SafeAreaContext.tsx:11:27 - error TS4111: Property 'NODE_ENV' comes from an index signature, so it must be accessed with ['NODE_ENV'].

11 const isDev = process.env.NODE_ENV !== 'production';
patlux commented 1 year ago

Ah sorry, I just realised this comes from the tsconfig.json:

{
  "compilerOptions": {
    "noPropertyAccessFromIndexSignature": true,
  }
}

But I'm not sure, why this doesn't occurred previosly...

jacobp100 commented 1 year ago

You can add "skipLibCheck": true

patlux commented 1 year ago

Is it already.

This is the full tsconfig:

{
  "compilerOptions": {
    "strict": true,
    "allowUnusedLabels": false,
    "allowUnreachableCode": false,
    "exactOptionalPropertyTypes": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noPropertyAccessFromIndexSignature": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,

    "checkJs": true,

    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "extends": "expo/tsconfig.base",
  "exclude": ["dist", "*.app/", "*.js"]
}
jacobp100 commented 1 year ago

Weird. I don’t get it for myself - however if you want to submit a PR I don’t see any harm merging it

jacobp100 commented 1 year ago

You need to "exclude": ["node_modules"]

dannyBies commented 1 year ago

You need to "exclude": ["node_modules"]

I've tried this but unfortunately it doesn't work. I've worked around it by adding this to *.d.ts file.

declare namespace NodeJS {
  interface ProcessEnv {
    readonly NODE_ENV: string
  }
}