-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
React stateless functional components #5675
Comments
I haven't tried your example but let ByComponentIoS = ({ name } : { name : string })=> <h1>{name}</h1> |
Could you explain why? |
You can take a look at the JS output: http://www.typescriptlang.org/Playground#src=let%20ByComponentIoS%20%3D%20(%7B%20name%20%3A%20string%20%7D)%20%3D%3E%20%22%22%3B%0D%0A It seems to use destructuring to extract "name" from the parameter and give it the name "string". |
Still, the error remains. TSX in 1.6 doesn't seem to support stateless functional components. Is there a plan to add support for those? |
#5596 will implement support for them |
@RyanCavanaugh Was this issue ever solved? Can you help with this perhaps? - http://stackoverflow.com/questions/34749564/typescript-react-0-14-stateless-functional-components/34752460 |
@tomenden the posted code has both syntactic and (unrelated) semantic errors, and the shown error refers to an identifier that isn't even in the provided code. I don't think that question can be answered as written today. |
@RyanCavanaugh OK, I will fix it, was written real quickly and perhaps without enough attention, my apologies. Could you please clarify how you would write in Typescript the following example from the official React Docs:
I see a similar issue open here - DefinitelyTyped/DefinitelyTyped#7468 |
@tomenden that is literally the code you would write. Expanded self-contained example: declare function getFish(x: any): any;
declare var Tank: any;
var Aquarium = ({species}) => (
<Tank>
{getFish(species)}
</Tank>
);
// OK
let x = <Aquarium species="rainbowfish" />
// Error
let y = <Aquarium specie="rainbowfish" />
|
@RyanCavanaugh - thank you for your replies, I appreciate your help.
I still get this error: Note the error is in regards to the usage of the Component (let x declaration). It seems as if the definition file for React is not allowing this as a valid JSX. I am using the latest React 0.14 definition file from tsd, what am I doing wrong? Thanks |
@RyanCavanaugh - Sorry for the misunderstanding, I just noticed now that this issue is marked as Typescript 1.8 milestone, and I am currently using the last stable release (1.75), since the combination of tslint and tslint-loader for webpack require this. I just tested the lines of code using the nightly builds (typescript@next) and it works |
Thanks for the follow-up -- glad the nightly build is working for you. Let me know if you see anything weird there. |
I get
error TS2605: JSX element type 'Element' is not a constructor function for JSX elements.Property 'render' is missing in type 'Element'.
How to fix it?
The text was updated successfully, but these errors were encountered: