Repository navigation
Method overloading does not work on TSX templates #9703
Copy link
Copy link
Closed
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
Activity
- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensus
on Jul 13, 2016 RyanCavanaugh commented
on Jul 13, 2016 MemberMore actionsDoes this work if the function is declared like so (without the explicit signatures)?
export function MainButton(props: ButtonProps | LinkProps): JSX.Element { const linkProps = props as LinkProps; if(linkProps.to) { return this._buildMainLink(props); } return this._buildMainButton(props); }
Ryan Cavanaugh (@RyanCavanaugh) it does not. :( - that throws:
Property 'to' does not exist on type 'IntrinsicAttributes & (ButtonType | LinkType)'It looks like only the first overloaded method is being evaluated. Moving
export function MainButton(linkProps: LinkProps): JSX.Element;above
export function MainButton(buttonProps: ButtonProps): JSX.Element;works as expected.
- addedCommittedThe team has roadmapped this issueThe team has roadmapped this issueand removedIn DiscussionNot yet reached consensusNot yet reached consensus
on Aug 22, 2016 RyanCavanaugh commented
on Aug 22, 2016 MemberMore actionsThis is actually rather complex but we're going to look at some targeted fix (mostly this example specifically and top-level union types in non-SFCs) in 2.1
Awesome!
1 remaining item
- modified the milestones: This milestone has been deleted, This milestone has been deleted
on Oct 31, 2016 +1
Reacted by Michael Alexander- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Jan 26, 2017 James Gillmore (@faceyspacey) Drew Wyatt (@drewwyatt) the fix is now in master....we will now use similar overload resolution logic to figure out SFC. Give it a try and let us know!
Reacted by Steven, Jed and Michael Alexander- locked and limited conversation to collaborators
on Jun 19, 2018
Metadata
Metadata
Assignees
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
TypeScript Version: 1.8.10
Code
Expected behavior:
I would expect the
buildSomeElement()function to not throw an error because the "to" attribute satisfies the second signature of the overloaded MainButton function (like what happens when this is called as a function and not used as a TSX element).Actual behavior:
The
buildSomeElement()function throws an error expecting anonClickattribute.