Last active
July 25, 2016 22:25
-
-
Save bezawislak/24026f8130a0fdee7a9d83117023c695 to your computer and use it in GitHub Desktop.
React CSSModules typings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'react-css-modules' { | |
interface Options { | |
allowMultiple?: boolean; | |
errorWhenNotFound?: boolean; | |
} | |
module Decorator { | |
interface Props { | |
styles?: any; | |
styleName?: string; | |
} | |
} | |
interface Decorator { | |
(defaultStyles: any, options?: Options): any; | |
} | |
const Decorator: Decorator; | |
export = Decorator; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'react-css-modules' { | |
interface Options { | |
allowMultiple?: boolean; | |
errorWhenNotFound?: boolean; | |
} | |
module CSSModules { | |
interface Props { | |
styles?: any; | |
styleName?: string; | |
} | |
} | |
interface CSSModules { | |
(defaultStyles: any, options?: Options): any; | |
} | |
const CSSModules: CSSModules; | |
export = CSSModules; | |
} |
For some reason it's not importing it properly. The actual function is in CSSModules.default
so I have to do something like this which is kind of ugly:
import * as CSSModules from "react-css-modules";
const CSSModulesDecorator = (CSSModules as any).default;
const styles = require("./MasonryMessage.scss");
@CSSModulesDecorator(styles)
export default class extends React.Component<MyProps, void> {
public render() {
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've added the
react-css-modules.d.ts
code to my custom d.ts file.Then in my component I do:
The TypeScript compiler is not complaining but I'm getting an error in the browser that says
TypeError: CSSModules is not a function
Any idea?