Skip to content

Conditional type breaks generic inference on jsx in 2.9 #24080

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

Closed
Kukkimonsuta opened this issue May 12, 2018 · 0 comments
Closed

Conditional type breaks generic inference on jsx in 2.9 #24080

Kukkimonsuta opened this issue May 12, 2018 · 0 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Kukkimonsuta
Copy link

Kukkimonsuta commented May 12, 2018

In code below constructing generic jsx element el1 works in 2.8.3, but breaks on 2.9.0-dev.20180512. Constructing el2 in 2.9.0-dev.20180512 works fine - shouldn't these be completely equivalent?

TypeScript Version: 2.9.0-dev.20180512

Search Terms: jsx conditional

Code

type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
class TestObject {
    a: string = '';
    b: number = 1;
    c: () => void = () => { };
}
interface TestProps<T> {
    model: T;
    foo: FunctionPropertyNames<T>;
}
function Test<T>(props: TestProps<T>) { return <></>; }
const model = new TestObject();

const el1 = <Test model={model} foo="c" />;
const el2 = <Test<TestObject> model={model} foo="c" />;

Expected behavior:
Compilation passes without errors.

Actual behavior:

test.tsx:14:33 - error TS2326: Types of property 'foo' are incompatible.
  Type 'string' is not assignable to type '"c"'.

14 const el1 = <Test model={model} foo="c" />;
                                   ~~~~~~~

Playground Link:
n/a since playground doesn't support jsx

Related Issues:
Possibly related to #23724

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants