How do you explicitly set a new property on `window` in TypeScript?

后端 未结 23 2191
青春惊慌失措
青春惊慌失措 2020-11-22 03:53

I setup global namespaces for my objects by explicitly setting a property on window.

window.MyNamespace = window.MyNamespace || {};
23条回答
  •  长情又很酷
    2020-11-22 04:16

    Using create-react-app v3.3 I found the easiest way to achieve this was to extend the Window type in the auto-generated react-app-env.d.ts:

    interface Window {
        MyNamespace: any;
    }
    

提交回复
热议问题