-
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
Add Support for Flow's new component syntax #58246
Comments
Unless this syntax is supported by JSX I can't see this happening at all. And until today I always thought flow is a type checker. TIL. |
I don't see the appeal either, but couldn't one react the same way to JSX itself? It's also a special syntax for react that has to be transpiled. |
Over time, JSX has proven to quite useful for a variety of scenarios. The React transform requires nothing more than a By contrast, these changes are much more React-specific. |
Remember when everyone said Flow was better because it wasn't adding transpiles-to-runtime stuff like enum and namespace to JS? TypeScript remembers π΄ |
The component syntax's advantage does not lie in its sugar; it's more about giving code semantics and allowing stricter type checks like return type being |
In all seriousness though, it doesn't seem that problematic to parse As far as I understand, their |
As others have said, React isn't the only user of JSX. Speaking as someone who's built a JSX framework, I could care less about more syntax sugar, JSX encompasses enough. Where it falls short is the limitations of typing, currently we can't do things like specifying "renders" types because JSX only allows one static return type It's unclear what the benefit of |
The biggest advantage IMO is the nicer handling of props. function MyComponent({ text = "Hello!", onClick }: { text: string, onClick: () => void }) {
return <div onClick={onClick}>{text}</div>;
} what the component syntax would allow: component MyComponent(text: string = "Hello!", onClick: () => void) {
return <div onClick={onClick}>{text}</div>;
} I would like to able to add a plugin to my tsconfig to have this functionality. |
π Search Terms
"syntax", "flow", "component", "tsx"
β Viability Checklist
β Suggestion
First of all, I'd like to apologize; this request doesn't satisfy the last three viability checks. But I couldn't submit this if I didn't mark them. That said, if someone from the typescript team could at least read this proposal, I would be extremely grateful.
Recently, flow has added a new syntax to write components and hooks. For react devs, that's huge, and as someone who uses (and loves) typescript, I'd love to have something like this on TSX files too.
I understand that there are a few limitations on what can be done in typescript; for example, I don't expect typescript to check the rules of hooks and other react-specific things. I know that things like Solid and Stencil also use JSX.
To be completely blunt: I WANT SUGAR. Most influencers covering this new feature mentioned that it's extremely unlikely that Typescript will implement it. But I decided to try anyway, even if just to understand the reason.
In a more practical sense, here's what I would expect to see in a realist scenario:
component
blocks would be transpiled intofunction
components.hook
blocks would be transpiled into functions.π Motivating Example
Here's the post that explains what I'm talking about: https://medium.com/flow-type/announcing-component-syntax-b6c5285660d0
π» Use Cases
The text was updated successfully, but these errors were encountered: