sindresorhus/conf

Use of #private forces Typescript users to target es2015 or later, use 3.8 or later

sandersn opened this issue · 3 comments

Found on Definitely Typed, where kap-plugin depends on conf. By default, Definitely Typed tsconfigs use the default target, which is (still) es5. This fails since ES5 doesn't have WeakMap, which #private emit depends on.

I would not personally use #private in conf:

  1. It doesn't have any information it needs to hide from other code, it just needs to prevent mistaken accesses to its internal details.
  2. The emitted Javascript is super weird, using WeakMaps unless you target ESNext.
  3. If you do target ESNext, Firefox and Safari don't support #private.
  4. Only Typescript 3.8 and above support #private at all.

I think Typescript-classic private is the right choice.

Another option is to ship multiple d.ts files using downlevel-dts, although I don't think the extra work is justified in this case.

  1. private is useless in practice as the it's not enforced for non-TS users, which is the majority.
  2. I'm fine with that.
  3. That doesn't matter. conf is for Node.js, not the browser.
  4. I'm fine with that.

In 7.1.2 the issue is still there