-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Should the $
function return HtmlElement?
#5074
Comments
Hm. I actually think the intention is the web Element interface here.
However, this name is already in scope and then TypeScript renames it. Cc
@aomarks for thoughts?
…On Tue, 30 Jan 2018, 22:04 Yasser Elsayed, ***@***.***> wrote:
Now it's typed to return a Polymer.Element, which almost always not going
to be the case. Why doesn't it just return an HtmlElement and let the
user cast it if needed?
https://github.com/Polymer/polymer/blob/99414511a5413c0e2d8ad7a494ba4ca015f6a534/types/lib/mixins/element-mixin.d.ts#L141
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5074>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFrDbyD8a24aOK6EepQubBeO9qZX4REJks5tP4P5gaJpZM4RzAjE>
.
|
As @TimvdLippe said, the intention is that the type is In the current 3.0-preview, modulizer converts the global |
Polymer defines its own `Element` class, shadowing the standard global `Element` class. This means that references to `Element` within the `Polymer` namespace inadvertently reference `Polymer.Element`. Here we define an alias of the global `Element`, so that we can reference it from declarations within the `Polymer` namespace. See microsoft/TypeScript#983 for general discussion of this shadowing problem in TypeScript. Fixes #5074
Polymer defines its own `Element` class, shadowing the standard global `Element` class. This means that references to `Element` within the `Polymer` namespace inadvertently reference `Polymer.Element`. Here we define an alias of the global `Element`, so that we can reference it from declarations within the `Polymer` namespace. See microsoft/TypeScript#983 for general discussion of this shadowing problem in TypeScript. Fixes #5074
Just sent #5084 that should fix this issue for 2.x by defining a global |
Thanks for the quick turnaround. |
Polymer defines its own `Element` class, shadowing the standard global `Element` class. This means that references to `Element` within the `Polymer` namespace inadvertently reference `Polymer.Element`. Here we define an alias of the global `Element`, so that we can reference it from declarations within the `Polymer` namespace. See microsoft/TypeScript#983 for general discussion of this shadowing problem in TypeScript. Fixes #5074
|
It is, but previously we were getting this subclass HTMLElement so if it is the expected behavior that is a breaking change which should be stated in the release note. Current TS workaround is const htmlElem = this.$.myId as HTMLElement; |
Whoops, looks like the accidental shadowing of |
|
Yup. Any ideas when this will be out though? Or which version it's targeting? |
@floribon Ok, after talking with the team, what you're seeing is working as intended. Previously, the typing for However, this was incorrect as you could have written code that expected all elements from That said, I think we could be open to a new API to make Typescript integration a bit easier, such as the magic tagname typing that |
@azakus thanks and sorry I missed the comment about the potential SVG match, it makes total sense. It may still be considered a potential breaking change or at least "meaningful change" even if it's a bug fix though. |
I have opened a PR Polymer/gen-typescript-declarations#100 to generate these types automatically |
I still think the returned type should be Let me know if you think this isn't the more common way of using the API, or if it's not what the API was meant for. |
@yebrahim Note that with |
Ah, that makes sense, my bad I didn't spot the difference. Thanks. |
Now it's typed to return a
Polymer.Element
, which almost always is not going to be the case. Why doesn't it just return anHTMLElement
and let the user cast it if needed?polymer/types/lib/mixins/element-mixin.d.ts
Line 141 in 9941451
The text was updated successfully, but these errors were encountered: