Search code examples
typescriptpolyfills

Polyfill Set in TypeScript but "Set is not defined"


I have es6 as one of the options in compilerOptions.lib in tsconfig.json, so I would assume that makes Set available in TypeScript (2.8.1). Most browsers work but some do not---I'm still logging Android and UC Mobile browsers that are generating this error:

Uncaught ReferenceError: Set is not defined

I added Set from polyfill.io but that doesn't seem to make a difference:

<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Set"></script>

Is there a way to polyfill Set in the rest of these browsers?


Solution

  • Seems cdn.polyfill.io doesn't recognize User-Agent of these devices. According to docs - you can force to return default polyfill if User Agent is unknown with unknown request parameter:

    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Set&unknown=polyfill"></script>