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

Error on type checking JSX children #15583

Closed
firewave-remo opened this issue May 4, 2017 · 1 comment
Closed

Error on type checking JSX children #15583

firewave-remo opened this issue May 4, 2017 · 1 comment
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter

Comments

@firewave-remo
Copy link

TypeScript Version: 2.3.2
I am struggeling with the new JSX children checking feature. I have already asked on Stackoverflow - TypeScript type checking JSX children but no answers so far, thats why i am asking here.

I cannot get the following code to work, but i think this should work according to the new feature.
Code

import * as React from 'react';
import * as ReactDOM from 'react-dom';

interface TestProps {
    children: string | JSX.Element;
}

const Foo = (props: TestProps) => <div>{props.children}</div>;

// Error on Foo
ReactDOM.render(
    <Foo>
        <div>Test</div>
    </Foo>,
    document.getElementById('content'),
);

Expected behavior:
No Errors

Actual behavior:
I get the following error on compilation:

TestTsxChildren> tsc --version
Version 2.3.2
TestTsxChildren> tsc
main.tsx(11,5): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & TestProps'.
  Type '{}' is not assignable to type 'TestProps'.
    Property 'children' is missing in type '{}'.

I hope you can tell me, what i am dooing wrong or maybe i missunderstood the new feature.

@yuit yuit added this to the TypeScript 2.3.3 milestone May 4, 2017
@yuit yuit self-assigned this May 4, 2017
@yuit yuit added Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter labels May 4, 2017
@yuit
Copy link
Contributor

yuit commented May 4, 2017

Thanks @VSDekar for report an issue. This error happens because the accompany react DTS is not updated. I have updated the DTS (DefinitelyTyped/DefinitelyTyped#16327) once that is merged, please update your react type files.

@yuit yuit closed this as completed May 4, 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
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter
Projects
None yet
Development

No branches or pull requests

2 participants