Skip to content

Instantly share code, notes, and snippets.

@insyri
Created March 31, 2022 01:12
Show Gist options
  • Save insyri/086e770b553b4ddcf43413905b78c50b to your computer and use it in GitHub Desktop.
Save insyri/086e770b553b4ddcf43413905b78c50b to your computer and use it in GitHub Desktop.
// There are two ways you can do this, the first being using a globals.d.ts file.
// Here, you would specify types like this..
// .d.ts
namespace NodeJS {
interface ProcessEnv {
SUPER_SECRET_TOKEN: string;
}
}
// You may have to specify this in the tsconfig.json file.
// tsconfig.json
{
"typeRoots": ["./path/to/global.d.ts", "./node_modules/@types"],
}
// Option two, in a .ts file.
// .ts
declare global {
namespace NodeJS {
export interface ProcessEnv {
SUPER_SECRET_TOKEN: string;
}
}
}
// https://dev.to/isthatcentered/typing-process-env-and-dealing-with-nodeenv-3ilm
// https://dev.to/asjadanis/parsing-env-with-typescript-3jjm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment