How do you add polyfills to Globals in typescript (modules)

后端 未结 2 633
深忆病人
深忆病人 2021-01-18 00:39

I was able to find a polyfill(on stack overflow) for Array#includes and add it to typescript but after adding a small import to my file it turned into a module(I understand

2条回答
  •  生来不讨喜
    2021-01-18 01:05

    You need to declare it in the global namespace:

    declare global {
      interface Array {
          includes(searchElement: T) : boolean;
      }
    }
    

    More

    Extending lib.d.ts is covered here : https://basarat.gitbooks.io/typescript/content/docs/types/lib.d.ts.html

提交回复
热议问题