Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`babel-plugin-react-css-modules` Typescript Type Checking

I am using babel-plugin-react-css-modules. It add the styleName property to HTML elements. Typescript doesn't recognize this property. I am pretty sure I need to extend something but nothing I have tried has worked.

I have tried declaring an Element in a '.d.ts' file to do declaration merging but I must be doing something wrong.

interface Element {
    styleName: string;
}

export const Wrapper: React.FC<IWrapperProps> = ({ children, style }) => (
  <div styleName="wrapper" style={style}>
    {children}
  </div>
);

UPDATE:

.d.ts not working

like image 790
hipstersmoothie Avatar asked Oct 11 '25 16:10

hipstersmoothie


1 Answers

Add @types/react-css-modules to your package.json and styleName will be recognized:

npm install @types/react-css-modules --save-dev
like image 141
Alexander van Oostenrijk Avatar answered Oct 16 '25 11:10

Alexander van Oostenrijk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!