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

Support a 'vue' option for JSX in .tsx files #13260

Closed
fallenleavesguy opened this issue Jan 3, 2017 · 14 comments
Closed

Support a 'vue' option for JSX in .tsx files #13260

fallenleavesguy opened this issue Jan 3, 2017 · 14 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: JSX/TSX Relates to the JSX parser and emitter Suggestion An idea for TypeScript

Comments

@fallenleavesguy
Copy link

[feature] Will typescript support compile tsx for vue.js?

@aluanhaddad
Copy link
Contributor

It would be nice. vuejs/vue#478

@fallenleavesguy
Copy link
Author

fallenleavesguy commented Jan 3, 2017

@aluanhaddad That is about using typescript with vue.js. However, we want something that can compile tsx to js for vue.js.

It would look like this in tsconfig.json.

"jsx": "react",

When use it with vue.js, we should use by changing react to vue.

"jsx": "vue"

@davidmoshal
Copy link

+1

@DanielRosenwasser DanielRosenwasser added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Jan 3, 2017
@aluanhaddad
Copy link
Contributor

aluanhaddad commented Jan 3, 2017

@yeluoqiuzhi I understand. The linked issue was also about using TypeScript with vue.js. I linked it to illustrate that there has been interest in this for a several years, and because it is an interesting discussion.
I think it would be great to see TypeScript's .jsx support leveraged by another framework.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jan 4, 2017

Right now the emit is pretty different between React and Vue's JSX emit. See the documentation here that shows what Vue JSX is transformed to.

@fallenleavesguy
Copy link
Author

Thanks. We would wait for typescript to support it, rather than use babel.

@HerringtonDarkholme
Copy link
Contributor

HerringtonDarkholme commented Jan 4, 2017

IMHO, the most significant difference is type checking. We can already use Babel + TS to transform code, so that would not be the hard part for users. Yet type checking is much more convoluted.

There are many libraries in wild to support Vue's type checking before official solution. Adopting which model needs proposal. @yeluoqiuzhi should know.

Even if we do only accept official library, type checking props and emit, two main interfaces in Vue, requires many changes. Unlike React, Vue's props are declared on the class as properties. There is no such thing like reactComponent.props where TypeScript can use to check JSX. Currently official library uses decorators to annotate props.

For custom event, Vue's JSX requires onEvent prefix for camelCase binding or on-event prefix for kebab-case binding, while React has no such event handler: every thing is prop. TS checker needs additional checking here. Other things like ref, slot should also be checked since they are components' API as well.

Finally, I would like to see Vue support can be done by #10159. I would expect Vue will be hot in 2017, but what about 2018? 2019? As a language,supporting only some specified libraries feels partisan.

Edit: thank Daniel for referring related issue in TS. Actually I have considered the same question before and gave up due to cyclic dependency.

@DanielRosenwasser
Copy link
Member

@HerringtonDarkholme see #12846 for general support of typing the Vue instance based on its input properties.

@DanielRosenwasser DanielRosenwasser added the Domain: JSX/TSX Relates to the JSX parser and emitter label Apr 19, 2018
@DanielRosenwasser DanielRosenwasser changed the title [feature] Will typescript support compile tsx for vue.js? Support a 'vue' option for JSX in .tsx files Apr 19, 2018
@andrei-markeev
Copy link

Would a PR be accepted that implements this?

@fallenleavesguy
Copy link
Author

I have move to react stack for a year...

@andrei-markeev
Copy link

I've created a PoC and it seems to work pretty well. Successfully used it for compiling a medium sized application (~2000 lines of Vue.js templates).

Can someone from the core team decide if a PR will be considered for this feature, i.e. --jsx vue mode? Affects small part of code, doesn't affect language design. Should I finalize the work?

Screenshot of a basic test:
image

In case anyone wants to peek at the code (work in progress):
andrei-markeev@56b951f

@david50407
Copy link

Although this issue is closed by author, I think there is still a good benefit to TypeScript and Vue.

How about re-open this issue? @aluanhaddad @DanielRosenwasser

@skyrpex
Copy link

skyrpex commented Mar 20, 2019

Maybe we should open a new issue?

@wartmanm
Copy link

I rebased and updated @andrei-markeev's PoC: wartmanm@vue-jsx.
I haven't used it extensively yet, but it passes all of Vue's tests in babel-plugin-transform-vue-jsx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: JSX/TSX Relates to the JSX parser and emitter Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

9 participants