'Use native private fields and methods with Typescript and ES5

I want to use a library that internally uses private fields such as #fieldName: any, by keeping my ES5 target.

When I try to transpile, I get: Private identifiers are only available when targeting ECMAScript 2015 and higher.

The only way to solve this is either target ES6 or higher, or put skipLibCheckas false.

Is it possible to avoid doing this? Maybe through other tools such as Babel?



Solution 1:[1]

TypeScript is a superset transpiler to vanilla JS. Babel is a JavaScript Next to JavaScript transpiler. I believe it is possible to transpile from TS to ES6 then have Babel pick it up from there and transpile into ES5. The setup might be a bit tricky but definitely achievable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 beautifulcoder