You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Event type (name string) doesn't get properly checked or suggestions when using addEventListener() on an Union of multiple HTMLElement typesΒ #58497
typeDivOrSpan=HTMLDivElement|HTMLSpanElementconstdivOrSpan=document.querySelector<DivOrSpan>(".could-be-div-or-span")!divOrSpan.addEventListener("typo",()=>{})// neither complain or suggest when first typingconstdiv=document.querySelector<HTMLDivElement>(".div")!div.addEventListener("click",()=>{})// doesn't complain either but get suggestions automatically as well as pressing ctrl+i
π Actual behavior
first one neither complain or suggest when first typing.
π Expected behavior
get suggestions automatically as well as pressing ctrl+i like the second one.
I suspect this is just a caveat of #29011, you're calling a union of overloaded and generic methods. Feels like a design limitation to me (just a nosy bystander and not a TS team member)
The caveats are that only one type in the list of union members is allowed to have overloads, and only one type within the list of union members is allowed to have type parameters.
I didn't fully understand that post, but I think it's a little different:
As Wesley Wigham (@weswigham) described, and as I understand, it will at least get an intersected signature (suggestion) between A and B? which is "2" in the above case. but in the similar case of HTMLDivElement and HTMLSpanElement, this seems doesn't work.
Activity
fatcerberus commentedon May 10, 2024
for the record: this is not a crash
LifeJustDLC commentedon May 11, 2024
Bruce Pascoe (@fatcerberus) sorry, I didn't have the time to bisect the versions.
fatcerberus commentedon May 11, 2024
No, I just meant that you put
but itβs not - the compiler didnβt crash. Itβs just not doing what you expect
jcalz commentedon May 11, 2024
I suspect this is just a caveat of #29011, you're calling a union of overloaded and generic methods. Feels like a design limitation to me (just a nosy bystander and not a TS team member)
LifeJustDLC commentedon May 12, 2024
Joe Calzaretta (@jcalz) Thanks for your insights.
I didn't fully understand that post, but I think it's a little different:
As Wesley Wigham (@weswigham) described, and as I understand, it will at least get an intersected signature (suggestion) between
AandB? which is"2"in the above case. but in the similar case ofHTMLDivElementandHTMLSpanElement, this seems doesn't work.RyanCavanaugh commentedon Jun 17, 2024
These signatures don't merge because the
thisvalue is different in the callbackstypescript-bot commentedon Jun 20, 2024
This issue has been marked as "Design Limitation" and has seen no recent activity. It has been automatically closed for house-keeping purposes.