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.

Property 'css' does not exist on type 'DetailedHTMLProps'

See original GitHub issue

Hey, thank you all for this wonderful library. I have recently adopted TypeScript and keep running into problems with the css prop. I couldn’t find anything about my issue in the sc typescript docs. Any help is greatly appreciated.

Environment

## System:
 - OS: Windows 10
 - CPU: (4) x64 Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
 - Memory: 16.58 GB / 23.94 GB
## Binaries:
 - Node: 11.6.0 - C:\Program Files\nodejs\node.EXE
 - Yarn: 1.15.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
 - npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
## package.json
 - "@types/styled-components": "4.1.14",
 - "typescript": "3.4.5",
 - "styled-components": "4.2.0",
 - "react": "16.8.6",
 - "react-dom": "16.8.6",
 - "react-scripts": "3.0.0",

Reproduction

https://codesandbox.io/s/6vp2yzj01k

Steps to reproduce

  1. Use TypeScript with styled-components
  2. Pass css prop to any React element

Expected Behavior

No type error

Actual Behavior

Type '{ children: (number | Element)[]; css: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.

  Property 'css' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.ts(2322)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

51reactions
peduartecommented, May 26, 2019

29reactions
yuchicommented, Jun 21, 2019

Apparently the problem lies in the fact that importing import {} from "styled-components/cssprop"; doesn’t resolve correctly on Yarn. Didn’t found the culprit, but found a solution. For everyone reaching this issue, you can extract all the content directly in a styled.d.ts (probably the same file where you define the theme shape):

import { CSSProp } from "styled-components";

declare module "styled-components" {
  export interface DefaultTheme {
    // Your theme stuff here
  }
}

declare module "react" {
  interface Attributes {
    css?: CSSProp;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - error TS2322: Property 'css' does not exist on type ...
Property 'css' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'. Here is a basic code example: import ...
Read more >
TS2322: Property 'css' does not exist... · Issue #1249 - GitHub
Example TS error:​​ TS2322: Type '{ children: Element; css: SerializedStyles; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes< ...
Read more >
property 'css' does not exist on type 'intrinsicattributes - You.com
I'm using React, Typescript and Swiper. I'm also on Shopify Hydrogen with server components. Which maybe preventing the files from finding the type...
Read more >
emotion中React的typeScript使用说明 - 会飞的猪9527
... 的css样式没有生效的,反而会报错,报错信息如: Property 'css' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, ...
Read more >
TypeScript - Emotion
These definitions infer types for css properties with the object syntax, ... On the other hand, there's no reason not to use @emotion/babel-plugin...
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