question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS2322: Property 'css' does not exist...

See original GitHub issue
  • emotion: version: 10.0.7
  • emotion-theming: 10.0.7
  • @emotion/core: version: 10.0.7
  • @emotion/styled: version: 10.0.7
  • @emotion/cache: version: 10.0.
  • react version: 16.7.0
  • typescript version: 3.2.4

Relevant code:

tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": false,
    "checkJs": false,
    "downlevelIteration": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "preserve",
    "lib": ["webworker", "esnext", "dom"],
    "module": "esnext",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": false,
    "noImplicitReturns": true,
    "noImplicitThis": false,
    "noUnusedLocals": false,
    "outDir": "./build/",
    "pretty": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": false,
    "strictNullChecks": false,
    "suppressImplicitAnyIndexErrors": true,
    "target": "esnext",
    "types": ["@emotion/core", "jest", "node", "webpack-env"]
  },
  "include": ["./src/**/*", "./monaco.d.ts"],
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "gamma.config.js"
  ]
}

Example TS error:

 TS2322: Type '{ children: Element; css: SerializedStyles; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.
Property 'css' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.

pragma

/** @jsx jsx */
import { jsx, css } from '@emotion/core'
import * as React from 'react'
...

Related Issues:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:27
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

341reactions
JesseVeldencommented, Nov 15, 2020

For Emotion 11 use the following configuration in your tsconfig.json until TypeScript 4.1 comes out:

{
  "compilerOptions": {
    "types": ["@emotion/react/types/css-prop"]
  }
}

Documentation: https://emotion.sh/docs/emotion-11#css-prop-types

82reactions
santyclazcommented, Apr 28, 2021

TL;DR: for React 17, Typescript 4.2, Emotion 11.1

tsconfig.json

{
  "compilerOptions": {
    ...
    "jsx": "react-jsx",
    "jsxImportSource": "@emotion/react",
    ...
  }
}

This seems to be the cleanest solution that works for me that does NOT require:

  1. adding a /// <reference types="@emotion/react/types/css-prop" /> to a .d.ts file
  2. adding a /** @jsxImportSource @emotion/react */ with any imports

See: Emotion TypeScript css prop docs


Additional Context:

Prior comments and the Emotion 11 docs linked in prior comments seemed to suggest that upgrading to a version of TypeScript > 4.1 would somehow resolve this issue (and by “resolve” I presumed this would mean removing the need for either the suggested tsconfig.json changes, or the other change suggested by a few others above on adding a /// <reference types="@emotion/react/types/css-prop" /> line in some .d.ts file in your codebase. Unfortunately this doesn’t seem to be case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - error TS2322: Property 'css' does not exist on type ...
However, i'm running into the following issue: error TS2322: Type '{ children: string; css: string; }' is not assignable to type ' ...
Read more >
property 'css' does not exist on type 'intrinsicattributes - You.com
ts(2322 ) Property children does not exist on type 'Intrinsic attributes and Props'. Asked Aug 4, 2020 • 27 votes 2 answers. QUESTION...
Read more >
TypeScript - Emotion
The easiest way to use the css prop with TypeScript is with the new JSX transform and the jsxImportSource TSConfig option (available since...
Read more >
【React, Typescript】Emotion入れたら “Property 'css' does ...
Emotion入れたら "Property 'css' does not exist on type &#039 ... TS2322: Property 'css' does not exist.
Read more >
'css' does not exist on type 'DetailedHTMLProps...' with new JSX
Error | 'css' does not exist on type 'DetailedHTMLProps. ... Type '{ children: Element[]; css: SerializedStyles; }' is not assignable to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found