-
Notifications
You must be signed in to change notification settings - Fork 441
Reduce symbol instantiations in lib.d.ts #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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! |
|
||
let implementedEventHandler = | ||
let implementis = i.Implements |> Array.map GetInterfaceByName | ||
[ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this returns the interface itself instead of the handlers it has?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. i could make it the interface name. but seemed the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like ElementTagNameMap
interface is always the same as HTMLElementTagNameMap
? Then make is an alias instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no they are different. not sure why though. i wanted to ask you about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do
type ElementListTagNameMap = { [K in ElementTagNameMap]: NodeListOf<ElementTagNameMap[K]> }
and avoid the loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Pt.print " {" | ||
Pt.increaseIndent() | ||
ownEventHandles |> List.iter EmitInterfaceEventMapEntry | ||
// Pt.printl "[x: string]: Event;" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
The |
A few changes:
this
types and instead add the overloads to every derived interface//cc: @zhengbli
Build diagnostics building
dom.genenrated.d.ts
before the change:After the change: