2017-03-25 576 views
0

我嘗試在typescript中使用respond-css-modules,但是我收到了無法將styleName添加到div元素的錯誤消息。這裏是碼。類型'HTMLProps <HTMLDivElement>'上不存在屬性'styleName''

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, 
} 
+1

你的意思是'className'? –

+0

而不是創建代碼的截圖,裁剪和上傳它,你應該複製和粘貼代碼本身 – Andreas

+0

我想添加一個類'根'div元素。但必須使用styleName屬性 – fariyAhill

回答

1

使用@類型/反應,CSS模塊。

npm install --save-dev @types/react-css-modules 

或者,

yarn add @types/react-css-modules --dev 
相關問題