kunokdev/cra-runtime-environment-variables

Referencing `window._env_` fails checks when using TypeScript

nhooey opened this issue · 1 comments

How would you propose to best get around Window not having a _env_ property, and TypeScript detecting this?

@nhooey Would something like this work for you?

You may extend window object:

export interface ExtendedWindow extends Window {
  _env_?: any;
}

and then when assigning its property, type its reference like so:

const { _env_ }: ExtendedWindow = window;

Alternatively, you may be interested in defining global type: https://stackoverflow.com/a/12709880/5426743