Reduce symbol instantiations in lib.d.ts#166
Conversation
|
This is so cool! It looks like this will be great news for custom elements. e.g. experimenting with the nightly build and some of the example code in microsoft/TypeScript#12311 it seems like this typechecks: class MySlider extends HTMLElement {
slide() {}
}
customElements.define('my-slider', MySlider);
interface HTMLKind {
'my-slider': MySlider;
}
document.createElement('my-slider').slide()So awesome! |
| [ for i' in implementis do | ||
| yield! match i' with | ||
| | Some i -> GetEventHandler i | ||
| | Some i -> if hasHandler i then [i] else [] |
There was a problem hiding this comment.
So this returns the interface itself instead of the handlers it has?
There was a problem hiding this comment.
yes. i could make it the interface name. but seemed the same
There was a problem hiding this comment.
Then the name of the variable should be changed to implementedInterface and other places, otherwise it can be confusing later
|
|
||
| let EmitElementTagNameMap () = | ||
| Pt.printl "interface ElementTagNameMap {" | ||
| Pt.increaseIndent() |
There was a problem hiding this comment.
It looks like ElementTagNameMap interface is always the same as HTMLElementTagNameMap? Then make is an alias instead
There was a problem hiding this comment.
no they are different. not sure why though. i wanted to ask you about that.
There was a problem hiding this comment.
Aha now I remember, the EmitHTMLElementTagNameMap only prints tag elements that either extends or implements the HTMLElement type.
| Pt.printl "interface ElementListTagNameMap {" | ||
| Pt.increaseIndent() | ||
| for e in tagNameToEleName do | ||
| Pt.printl "\"%s\": NodeListOf<%s>;" (e.Key.ToLower()) e.Value |
There was a problem hiding this comment.
We can do
type ElementListTagNameMap = { [K in ElementTagNameMap]: NodeListOf<ElementTagNameMap[K]> }and avoid the loop
There was a problem hiding this comment.
That is what i had earlier, then changed it. the issue is that NodeListOf has a constraint that T extends Node. we can not verify this constraint on ElementTagNameMap[K] unless i add a string indexer. adding the indexer makes the language service experience of the signature help much worse. so this is a work around for that.
TS.fsx
Outdated
| Pt.print " {" | ||
| Pt.increaseIndent() | ||
| ownEventHandles |> List.iter EmitInterfaceEventMapEntry | ||
| // Pt.printl "[x: string]: Event;" |
|
The |
A few changes:
thistypes and instead add the overloads to every derived interface//cc: @zhengbli
Build diagnostics building
dom.genenrated.d.tsbefore the change:After the change: