-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typings): make environment globals work everywhere with proper DX
- Loading branch information
Showing
1 changed file
with
21 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
declare namespace NodeJS { | ||
interface ExtendedProcessEnv { | ||
env: { | ||
NODE_ENV?: 'production' | 'development' | 'test'; | ||
LAGE_PACKAGE_NAME?: string; | ||
CI?: string; | ||
TF_BUILD?: string; | ||
}; | ||
// env: { | ||
NODE_ENV?: 'production' | 'development' | 'test'; | ||
LAGE_PACKAGE_NAME?: string; | ||
CI?: string; | ||
TF_BUILD?: string; | ||
} | ||
|
||
/** | ||
* NOTE: | ||
* proper DX and type-checking wont work whenever a library that uses `@types/webpack-env` is used in your code. | ||
* extending/creating ProcessEnv interface which is used in @types/node to define `process.env` | ||
* | ||
* WHY?: | ||
* - `@types/webpack-env` defines `env` as `any`, thus making extension incompatible. @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/webpack-env/index.d.ts#L275 | ||
* - `@storybook/addons` module type definitions internally reference `@types/webpack-env` so `process.env` type checking/DX wont work in all storybook configs/files | ||
* NOTE: | ||
* To make it work with and without node globals it need to use same token name | ||
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v12/globals.d.ts#L764 | ||
*/ | ||
export interface ProcessEnv extends ExtendedProcessEnv {} | ||
|
||
/** | ||
* extending/creating `Process` interface which is used in @types/node to define `process` global | ||
* | ||
* NOTE: | ||
* To make it work with and without node globals it need to use same token name | ||
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v12/globals.d.ts#L883 | ||
*/ | ||
export interface Process { | ||
env: ProcessEnv; | ||
} | ||
} | ||
|
||
declare var process: NodeJS.ProcessEnv; | ||
declare var process: NodeJS.Process; |