How to type .env in Expo Typescript project ( Expo SDK 49 )

Please provide the following:

  1. SDK Version: 49.0.5
  2. Platforms(Android/iOS/web/all): all
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

I have followed the documentation on how to add .env in an Expo project environment variables
I keep getting the type error Property 'EXPO_PUBLIC_API_URL' does not exist on type 'typeof env'.
my .env

EXPO_PUBLIC_API_URL=someurl

How do I add EXPO_PUBLIC_API_URL to typeof .env?

I just able to make it works.
So I create a new file from the root directory of Expo project: global.d.ts

So I define a list of env params like this:

declare global {
  namespace NodeJS {
    interface ProcessEnv {
      EXPO_PUBLIC_API_URL: string | undefined;
      EXPO_PUBLIC_MORE_KEY: string | undefined;
      // etc...
    }
  }
}
export { }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.