Skip to content
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

Typescript: styleName usage with @types/react@^17 #292

Open
eugeneoshepkov opened this issue Nov 24, 2020 · 4 comments
Open

Typescript: styleName usage with @types/react@^17 #292

eugeneoshepkov opened this issue Nov 24, 2020 · 4 comments

Comments

@eugeneoshepkov
Copy link

eugeneoshepkov commented Nov 24, 2020

There's a problem with extending Attributes and HTMLAttributes interface with styleName with @types/react@^17. It simply has no effect:

Property 'styleName' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.

"@types/react-css-modules": "^4.6.2",

image

@yinsang
Copy link

yinsang commented Jul 22, 2021

add file to your project, named react-css-module.d.ts.

declare namespace React {
  interface Attributes {
    styleName?: string | undefined;
  }
  interface HTMLAttributes<T> {
    styleName?: string | undefined;
  }
  interface SVGAttributes<T> {
    styleName?: string | undefined;
  }
}

@Anatoool
Copy link

I have the same issue with "@types/react-css-modules": "^4.6.4",

@max-mykhailenko
Copy link

@yinsang your solution doesn't work with
typescript 4.3.5 and react 17.0.2
Got Property 'styleName' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'

Maybe you have some thoughts how to fix that

@leevben
Copy link

leevben commented Apr 29, 2024

This works for me(React@18.x)
1.

// global.d.ts
declare namespace JSX {
  interface IntrinsicAttributes {
    styleName?: string;
  }

}
declare namespace React {
  interface Attributes {
    styleName?: string;
  }
  interface HTMLAttributes<T> {
    styleName?: string;
  }
  interface SVGAttributes<T> {
    styleName?: string;
  }
}
  1. turn off this eslint rule
    "react/no-unknown-property": "off"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants