-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Method overloading does not work on TSX templates #9703
Comments
Does 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);
} |
@RyanCavanaugh it does not. :( - that throws:
|
It looks like only the first overloaded method is being evaluated. Moving
above
works as expected. |
This 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 |
@faceyspacey @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! |
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 anonClick
attribute.The text was updated successfully, but these errors were encountered: