danvk / effective-typescript

Effective TypeScript 2nd Edition: 83 Specific Ways to Improve Your TypeScript

Home Page:https://effectivetypescript.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In defense of interface: Using declaration merging to disable bad parts

danvk opened this issue · comments

In defense of interface: Using declaration merging to disable bad parts

https://effectivetypescript.com/2021/06/03/interface/

Comment by Serhii on 2021-07-07 09:13:

Here I have overloaded BuiltIn CallableFunction

Declaration merging deserves all the hate it gets. I can’t declare a class named Plugin in one of my files because it conflicts with the DOM Plugin class? That’s user-antagonistic behavior. Local names in JS shadow global names, so it’s really annoying that TS behaves completely differently.

It’s just leftover cruft from TypeScript's pre-ESM days that needs to be eradicated.

Monkeypatching type definitions can be useful but there should be a way to explicitly declare overrides, instead of having to exploit an ill-conceived feature to do so.