我尝试在 typescript 中使用 react-css-modules,但我收到一条错误消息,无法将 styleName 添加到 div 元素。这是代码。
import * as Immutable from 'immutable';
import * as React from 'react';
import * as CSSModules from 'react-css-modules';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
const styles = require<any>('./style.scss');
interface RootProps {
data: Immutable.List<string>;
dispatch: Dispatch<any>;
}
@CSSModules(styles)
export class Root extends React.Component<RootProps, {}>{
render() {
return (
<div styleName='root'>
Hello
</div>
)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Root);
我收到此错误消息:'Property 'styleName' does not exist on type 'HTMLProps<HTMLDivElement>'
和 tsconfig
"compilerOptions": {
"target": "es5",
"moduleResolution": "node",
"jsx": "react",
"experimentalDecorators": true,
"removeComments": true,
"preserveConstEnums": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"sourceMap": true,
}