-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
TS2322: 'css' does not exist on type 'DetailedHTMLProps...' with new JSX runtime w/ NextJs #2111
Comments
For the JSX namespace to be resolved automatically with the new automatic runtime you need to be on TS 4.1 which is supposed to be released this week. This is mentioned in that linked post:
There is also mentioned an intermediary solution of adding |
So I have to update the TS version to 4.1 to make use of the new JSX runtimes. Gotcha, thanks. |
I have to reopen this issue because I still see it after upgrading the typescript to 4.1.2. The reproduction steps with my sample repo are still valid. |
Please just apply this patch: diff --git a/tsconfig.json b/tsconfig.json
index c8399a6..983beb9 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -21,7 +21,8 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
- "jsx": "preserve",
+ "jsx": "react-jsx",
+ "jsxImportSource": "@emotion/react",
"baseUrl": "./src"
},
"include": [ This probably ain't mentioned anywhere in the docs - if you'd like to prepare one I would appreciate a PR for this. |
Thanks. That works.
|
Oh - I haven't realized that I have also thought that |
...and specify jsxImportSource for TypeScript. @see https://emotion.sh/docs/emotion-11#css-prop-types @see emotion-js/emotion#2111 (comment)
* chore(deps): update emotion monorepo to v11 * chore(deps): update emotion to v11 * chore(deps): temporarily add emotion css prop types globally * chore(deps): explicitly include className prop on stylable components ...and specify jsxImportSource for TypeScript. @see https://emotion.sh/docs/emotion-11#css-prop-types @see emotion-js/emotion#2111 (comment) * chore(deps): avoid the need for explicit className prop on AdditionalInfo children Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Justin Hall <[email protected]>
This required a change to the tsconfig. I found the current solution here: emotion-js/emotion#2111 (comment)
This required a change to the tsconfig. I found the current solution here: emotion-js/emotion#2111 (comment)
For those coming here with the current vesions of emotion.d.ts /// <reference types="@emotion/react/types/css-prop" />
import '@emotion/react';
import { CustomThemeInterface } from '.';
declare module '@emotion/react' {
export interface Theme extends CustomThemeInterface {}
} @Andarist I may open a PR to update the docs with this, if you wish me to. |
A PR documenting this would be very much appreciated. I wonder - are there any open issues in Next about this? Are there any arguments for maintaining the current behavior? |
Happy to help! 🎉 PR coming right up.
Based on what I've read looking through their "issues" on this subject (i.e. I'm speculating lol), they do their own JSX handling under the hood, so delegating it breaks their own runtime, performance optimisations, etc. On the bright side, they seem to be porting the relevant babel plugins etc. to SCW (their own compiler), which may include the JSX runtime config option. 👍 Update: Looking deeper into why my app didn't seem to be satisfied with just the babel plugin and jsxImportSource, I found my problem was caused by incorrect usage of the css props that may have been deprecated at some point. That said, even though the solution I posted before may still be useful for some people, I can now confirm the /// reference doesn't seem necessary in NextJS + Typescript (as long as you're using the Babel plugins). Ping @srmagura, re resolution to our earlier conversation. |
Current behavior:
I have used NextJs v10.0.1 and emotionJs v11.0.0. I installed the
@emotion/babel-plugin
and followed the new jsx runtime setup with NextJs in this page.I still get errors when input
css
properties in the JSX react element.To reproduce:
nvm use || nvm install npm install npm run build
Expected behavior:
Babel should map
css
properties in JSX elements and typescript should not output type error TS2322 forcss
in JSX elements.Environment information:
react
version: 17.0.1@emotion/react
version: 11.0.0nextjs
version: 10.0.1typescript
: 4.0.5The text was updated successfully, but these errors were encountered: