How to extend the 'Window' typescript interface

前端 未结 2 812
你的背包
你的背包 2020-12-29 03:20

In my example, I\'m trying to extend the TS Window interface to include a polyfill for fetch. Why doesn\'t matter. The question is \"how do I tell T

2条回答
  •  不知归路
    2020-12-29 03:25

    You need the declare global

    declare global {
      interface Window {
        fetch:(url: string, options?: {}) => Promise
      }
    }
    

    This works then:

    window.fetch('/blah').then(...); 
    

提交回复
热议问题