-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
JSX .tsx support #15
Comments
I'm really not familiar with .tsx. Is the only thing we should do is check if it's a A failing test for this would be nice as would allow me to fix it more easily and make sure I don't misunderstand the problem :). |
Correct:
|
Also, disregard my first example because dom-chef types aren't there yet. This should be your test, I think: // index.test-d.tsx
import {expectType} from 'tsd-check';
import React from 'react';
class Welcome extends React.Component() {
constructor() {
super();
return <h1>Hello</h1>;
}
}
expectType<Welcome>(<Welcome/>); And this would be the JSX-less equivalent example, which I just tested and works: // index.test-d.ts
import {expectType} from 'tsd-check';
import React from 'react';
class Welcome extends React.Component() {
constructor() {
super();
return React.createElement("h1", null, "Hello");
}
}
expectType<Welcome>(React.createElement(Welcome, null)); |
It's really stupid that we're forced to use a |
Thanks @bfred-it for the test case! I'll see what I can do. |
I tried looking into this, but not sure if I understand the problem correctly. The thing is that the class Welcome extends React.Component() {
constructor() {
super();
return <h1>Hello</h1>;
}
}
class Unicorn extends React.Component() {
constructor() {
super();
return <h2>Unicorn</h2>;
}
}
expectType<Welcome>(<Unicorn/>); The reason is that So my question actually is, why do we need I'm just wondering and clarifying so that we are all on the same page :). I could totally add it for convenience, but I want to know the 'why'. |
If you enable JSX in TypeScript the type should be |
On a sidenote, I installed |
Yeah, JSX types are awful, The expectType<JSX.Element>(<div/>); I made a mistake in my OP |
Even in that case I'm not entirely sure that As for the |
But what to do in case of class Unicorn extends React.Component {
constructor(props) {
super(props);
}
render() {
return <h1>Unicorn</h1>;
}
}
expectType<Unicorn>(<Unicorn />); Or would it be enough that Checking it against expectType<JSX.Element>(<Unicorn />); |
I think technically React.createElement(Unicorn);
// appears to be of type
React.ComponentElement<{}, Unicorn> Also: React.createElement('div');
// appears to be of type
React.DetailedReactHTMLElement<React.HTMLAttributes<HTMLElement>, HTMLElement>` |
For some reason, this doesn't fail. expectType<React.ComponentElement<{}, Welcome>>(<Unicorn />);
expectType<React.ComponentElement<{}, Welcome>>(React.createElement(Unicorn)); Let's just enable this feature and see how it goes. |
I could use some help testing #36 to see if this is what is expected :). |
Released as |
Thank you |
Thank you for opening the issue and helping me understand the problem :) |
The text was updated successfully, but these errors were encountered: