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

后端 未结 23 2635
青春惊慌失措
青春惊慌失措 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:13

    If you are using Typescript 3.x, you may be able to omit the declare global part in the other answers and instead just use:

    interface Window {
      someValue: string
      another: boolean
    }
    

    This worked with me when using Typescript 3.3, WebPack and TSLint.

提交回复
热议问题