-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 Custom JSX Pragma #9582
Comments
I have a different view consider this proposal Your requirement can be implements via " custom syntax tree transformations " . So I don't think it's necessary for us to increase tsconfig 's complexity. |
And I think that's a great idea, however the tsconfig already has an option for JSX (that only supports React.) I don't see why we'd support just the first half of the function call. |
@WanderWang this is very much a userland feature. Most users of TypeScript would not be compelled to extend TypeScript itself simply to account for a common use-case. My suggestion could replace the existing Currently, TypeScript forces users to build shims for non-React JSX use-cases, which is significantly more cumbersome than needing to know about another (or a different) configuration property. |
workaround: import * as h from "someplace";
const hyper = {createElement: h} |
@basarat yes, this is what people currently do. However, this is a second-class experience and difficult to explain in documentation. |
@basarat that is exactly that - a workaround. It seems that there should be a better way of doing this. |
No discussion, no nothing. Sad. |
My use-case is to support JSX within skate.js. skatejs has a hyperscript compliant API |
Accepting PRs for a flag
|
Sweet, someone submit a PR |
Be the PR you want to see in the world 😉 |
I would, but I've never used TypeScript and already have tons to maintain 😛 |
I'll raise a PR. |
In the case of I think we should require
|
sounds reasonable. |
I've raised the PR — #11267. |
For future readers — {
"compilerOptions": {
"jsx": "react",
"jsxFactory": "h"
}
}
The above configuration will get you going. |
Edit: updated the jsxFactory property name in comment above. |
@mhegazy I get this error —
|
Use |
This is awesome. Kudos for baking this as a compiler param. |
<div>Hello</div> should compile to: ({h}) => h('div', {}, 'Hello'); and them React could do: (({h}) => h('div', {}, 'Hello'))({
h: React.createElement,
}); |
Hi. I've searched through the various issues (as well as other places this has been discussed) and I don't see a current open issue to address the lack of custom JSX pragma support.
As discussed elsewhere, other transpilers allow specifying any function name to insert when producing hyperscript from JSX. It's worth noting that hyperscript predates React, and is a format shared by a large number of libraries entirely separate from the React project. Currently, TypeScript only allows configuration of an Object on which to invoke
.createElement()
, however the original implementations and many descendants thereof simply useh()
. You can read my attempt to document some of the context and background here.The configuration would presumably look something like this:
... and the output would look like:
Has this been bypassed for feasibility reasons? If not, I think it would be a valuable addition.
The text was updated successfully, but these errors were encountered: