-
Notifications
You must be signed in to change notification settings - Fork 362
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
Error using Fragment shorthand in React Typescript project #564
Comments
@breadadams does this still break if you set the following in your {
"compilerOptions": {
"jsx": "preserve"
}
} |
Apparently yes @developit, we already have that property set - sorry, should have shared our tsconfig: {
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"jsx": "preserve"
},
"include": ["src"]
} I think it's pretty much the default from a CRA. |
I think we are accidentally processing JSX in TypeScript here: Lines 553 to 554 in 8cc0d7b
We should probably be doing it in Babel (draft PR), since TypeScript has been dragging their heels on supporting configurable Fragment pragma for over a year. Now, if I'm wrong about the above, you should be able to get fragment syntax working properly by setting the microbundle --jsxFragment React.Fragment |
It seems like we're allowing TypeScript to transpile JSX, when we could be allowing Babel to do so. Having TypeScript pass-through JSX to babel would mean we only have to support it being configurable in one place. (hoping this fixes #564) Co-authored-by: Leah <me@hrmny.sh> Co-authored-by: Leah <github.leah@hrmny.sh>
After recently migrating a project over from Flow to TypeScript I've noticed a difference when using the Fragment shorthand (
<></>
). We have the following utility:With Flow, it compiled as follows:
After moving to TS though, it doesn't take
Fragment
from React (eg.n
):Resulting in the following error when using the bundle:
Full stack trace
As a temporary solution we've replaced the shorthand with an imported
Fragment
and it now compiles as expected:Versions
0.12.0-next.8
16.12.0
3.7.5
Build script:
microbundle --jsx React.createElement --format cjs,umd
The text was updated successfully, but these errors were encountered: