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
Property 'css' does not exist on type 'DetailedHTMLProps' #2528
Comments
Linking https://spectrum.chat/styled-components/help/css-prop-with-typescript~61a24960-8df6-48e5-bf25-046656a58b5c with @sami616's solution as seen in https://codesandbox.io/s/m48n2v0wwy by declaring an index.d.ts file. Unfortunately, this didn't work in my actual project I assume because I'm using I have a project structure like the following:
And inside my index.d.ts, I try to add the css prop like this /// <reference path="../../node_modules/@types/react/index.d.ts"/>
import { DOMAttributes } from "react";
declare namespace React {
interface HTMLAttributes<T> extends DOMAttributes<T> {
css?: any;
}
} |
Hey there, thanks for using styled-components but we don’t maintain the types here. For TS-specific questions I’d recommend DefinitelyTyped or some online help forum like SO or Spectrum |
Apparently the problem lies in the fact that importing import { CSSProp } from "styled-components";
declare module "styled-components" {
export interface DefaultTheme {
// Your theme stuff here
}
}
declare module "react" {
interface Attributes {
css?: CSSProp;
}
} |
@yuchi Your solution worked for me. I had to reload VSCode before it got picked up. The following also seems to work and appears more type correct to me: declare module "react" {
interface HTMLAttributes<T> extends DOMAttributes<T> {
css?: CSSProp;
}
} |
solutions above worked, but seems order matters, so |
The above solution worked for me. But why isn't the |
@omarryhan because it must be enabled specifically through the Babel Plugin or Babel Macro. |
What do you do if you're already using typeRoots in tsconfig.json, which isn't compatible with types? |
Also adding this |
Hey, thank you all for this wonderful library.
I have recently adopted
TypeScript
and keep running into problems with thecss
prop. I couldn't find anything about my issue in the sc typescript docs. Any help is greatly appreciated.Environment
Reproduction
https://codesandbox.io/s/6vp2yzj01k
Steps to reproduce
css
prop to any React elementExpected Behavior
No type error
Actual Behavior
The text was updated successfully, but these errors were encountered: