我想用Flow與draft-js。正確的方式來設置流稿與草稿-js
的package.json依賴
...
"dependencies": {
"draft-js": "^0.9.1",
"immutable": "^3.8.1",
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"devDependencies": {
"flow-bin": "^0.37.4"
}
我通過運行flow-typed install
安裝了flow-typed類型定義。
這裏是我從draft-js文檔複製的一些稍微修改過的代碼,我試圖用流驗證。
index.js
// @flow
import React from 'react';
import ReactDOM from 'react-dom';
import {Editor, EditorState} from 'draft-js';
class MyEditor extends React.Component {
state: {
editorState: EditorState
}
onChange: Function;
constructor(props) {
super(props);
this.state = {editorState: EditorState.createEmpty()};
this.onChange = (editorState) => this.setState({editorState});
// gives type error, as expcted
let a :string = 10;
const editorState :EditorState = this.state.editorState;
// should be a type error, editor.getCurrentContent() returns type ContentState
const content :string = editorState.getCurrentContent();
}
render() {
return (
<Editor editorState={this.state.editorState} onChange={this.onChange} />
);
}
}
ReactDOM.render(
<MyEditor />,
document.getElementById('container')
);
.flowconfig
[ignore]
.*\/node_modules\/draft-js\/lib\/.*.js.flow.*
[include]
[libs]
.*\/node_modules\/draft-js\/lib\/.*.js.flow.*
[options]
esproposal.class_static_fields=enable
suppress_type=$FlowIssue
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue
然而,當我運行flow
命令,當我打電話API草案-JS我沒有得到任何錯誤。在這裏設置流程以用於草稿的正確方法是什麼?