#Transpiling core JS features with TS with polyfill on top
17 messages · Page 1 of 1 (latest)
@copper bear TS doesn't transpile APIs - you'd generally want to load a polyfill.
If you have added a polyfill (maybe import core-js does that), you'd want to update your lib config in tsconfig to say what all is available due to the polyfills.
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
☝️ has a list of the lib values and what APIs they enable
Yeah, lib: [ "es5 ]" says you only have access to ES5 APIs, which isn't what you want.
You say target: ES5 because that's the syntax that TS compiles down to. But for lib you have to list the stuff you want to include.
If you read the link I sent, replaceAll is ES2021
Yes, like I said at the start:
TS doesn't transpile APIs - you'd generally want to load a polyfill.
TS will not replace replaceAll with other code, it just doesn't do that. It transpiles syntax features (like arrow functions and classes can be transpiled to ES5 equivalents), but it doesn't transpile APIs like .replaceAll.
The point is that the core-js import should add a polyfill so that q.replaceAll works at runtime. It doesn't change your code.
I'm not sure what you mean? You want to do q.replaceAll and have it automatically change to someting like:
import replaceAllPolyfill from "somewhere";
replaceAll(q)
I'm not aware of anything that does that.
It's very common to polyfill APIs, not transpile them.
Okay, I'm not aware of any tool that does that.
It's much harder to analyze API usage and polyfill it.
Do you replace any call to replaceAll with a custom implemetation? How do you know that q.replaceAll is actually String.prototype.replaceAll and not something else?