Skip to content
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

Stateless functions used as JSX components don't support overloading #15784

Closed
apexskier opened this issue May 11, 2017 · 1 comment
Closed
Labels
Duplicate An existing issue was already created

Comments

@apexskier
Copy link

TypeScript Version: 2.2.1

Code

import * as React from "react";

interface A {
    requiredA: string;
}
interface B {
    requiredB: string;
}

function TestA(props: A): JSX.Element;
function TestA(props: B): JSX.Element;
function TestA(props: A | B) {
    return <div />;
}

<TestA requiredA={"test"} />;
<TestA requiredB={"test"} />;

function TestB(props: B): JSX.Element;
function TestB(props: A): JSX.Element;
function TestB(props: A | B) {
    return <div />;
}

<TestB requiredA={"test"} />;
<TestB requiredB={"test"} />;

Expected behavior:

This should compile. Overloading function definitions should allow props of either A or B.

Actual behavior:

The compiler respects only the first overload signature. Visual studio code correctly doesn't warn inline.

src/test.tsx(17,1): error TS2324: Property 'requiredA' is missing in type 'IntrinsicAttributes & A'.
src/test.tsx(17,8): error TS2339: Property 'requiredB' does not exist on type 'IntrinsicAttributes & A'.
src/test.tsx(25,1): error TS2324: Property 'requiredB' is missing in type 'IntrinsicAttributes & B'.
src/test.tsx(25,8): error TS2339: Property 'requiredA' does not exist on type 'IntrinsicAttributes & B'.
@mhegazy
Copy link
Contributor

mhegazy commented May 11, 2017

This should be fixed in 2.3. see #9703

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 11, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants