Search code examples
typescriptprivate-members

When does the TS compiler output EMCAScript Private Fields using WeakMaps?


I'm aware that the TypeScript compiler can use a workaround via WeakMap to "polyfill" ECMAScript Private class fields, but when does/doesn't it do that?


Solution

  • According to the official documentation, the TypeScript compiler uses WeakMaps when the target output is configured to ES2021 or less, and otherwise outputs ECMAScript private class fields.