Description
I noticed that recently a lot of new APIs are added to lib.d.ts
. Of cause this is a good thing, however my code breaks badly because of such update.
Previously I had added a lot of declarations in my code for HTML5 APIs that were missing in lib.d.ts
. Now some of them are added to lib.d.ts
, and I get quite a few "duplicated identifier" errors. For example, I had added this piece to play with fullscreen:
interface Document {
//...
fullscreenEnabled: boolean;
mozFullScreenEnabled: boolean;
webkitFullscreenEnabled: boolean;
}
Now fullscreenEnabled
and webkitFullscreenEnabled
are available in lib.d.ts
, and my code breaks, and I have to remove them. However, you are still missing mozFullScreenEnabled
right? -- well, waiting for the next break.
Web platforms are constantly evolving, it is not practical to expect lib.d.ts
always up to date, so developers just have to write such compensating declarations from time to time. Can TS avoid such breaks? I have a few ideas:
- Allow duplicated members in multiple interface declarations, as long as they are identical. In the fullscreen API example above, tsc should not fire errors. Optional compiling warnings are acceptable, to assist developers to remove redundant codes at convenient time.
- Make
lib.d.ts
overridable. When tsc find conflictions betweenlib.d.ts
and client codes, it should pickup declarations in client codes. This is because declarationslib.d.ts
may contain bugs, developers should be allowed to workaround them. E.g.MutationObserver
's constructor was missing a parameter for a long time. Again, optional warnings are welcomed.
What do you think?