microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.64k stars 12.44k forks source link

Provide lib for modern DOM #21150

Open jods4 opened 6 years ago

jods4 commented 6 years ago

This is basically a re-opening of #2910, which @mhegazy asked me to do.

Nowadays TS has the lib compiler option that allow users to selectively choose which core definitions to include or not based on their target.

It would be nice to add a new option similar to dom and dom.iterable for users targetting a modern DOM runtime. Not sure how to name this since W3C has moved from releases to a "living standard" model.

For example, the living standard includes interfaces ChildNode with methods after, before, remove and replaceWith; ParentNode with methods prepend and append.

Those methods have been in Firefox and Chrome for a long while, they're in preview in Edge (17035+).

They are very convenient and there's no reason a dev that targets modern browsers shouldn't be able to do "lib": "dom.living" and use them.

Unfortunately I am not sure if there's a list somewhere of all those new features... except going through the whole standard :(

mhegazy commented 6 years ago

We have been more open in taking in these declarations into lib.d.ts. so feel free to send us a PR adding the new interfaces. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

JoshuaKGoldberg commented 6 years ago

Related: https://github.com/Microsoft/TSJS-lib-generator/issues/327

jods4 commented 6 years ago

My understanding is that the basis used to generated DOM lib is the MS Edge definitions. Since those features have shipped (see https://twitter.com/MSEdgeUpdates/status/1000421335229784064 ) can we expect to see them in the next TS release? I hoped they would be in 2.9, too bad they're not :(

mhegazy commented 6 years ago

We are moving to generate the lib from the spec directelly. See https://github.com/Microsoft/TSJS-lib-generator/tree/master/inputfiles/idl

jods4 commented 6 years ago

👍 that would fix it as well!

chharvey commented 5 years ago

I noticed TypeScript v3.1 introduced a lot of new DOM functionality, including (among the most common):

The release notes indicate that part of lib.d.ts is now generated programmatically from the WHATWG DOM Spec. 🎊