我有一个文件使用scss与css模块,如下所示:
import styles from './Login.scss';
webpack构建工作正常但我得到一个流错误: Required Module Not Found
在我的.flowconfig中
[ignore]
.*/node_modules/fbjs/.*
.*/app/main.js
.*/app/dist/.*
.*/release/.*
.*/git/.*
[include]
[libs]
[options]
esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable
esproposal.export_star_as=enable
module.name_mapper.extension='css' -> '<PROJECT_ROOT>/flow/CSSModule.js.flow'
module.name_mapper.extension='styl' -> '<PROJECT_ROOT>/flow/CSSModule.js.flow'
module.name_mapper.extension='png' -> '<PROJECT_ROOT>/flow/WebpackAsset.js.flow'
module.name_mapper.extension='jpg' -> '<PROJECT_ROOT>/flow/WebpackAsset.js.flow'
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue
Run Code Online (Sandbox Code Playgroud)
我也看过https://github.com/facebook/flow/issues/338但它确实没有任何解决方案.
有没有人找到解决这个问题的方法?
我有定义的全局类型/flow-typed/redux.flow.js:
declare type Action = {|
+type: string,
+payload: any,
|}
declare type State = {|
+ui: UI,
+user: User,
+team: Team,
+projects: Project[],
+profile: Profile,
|}
declare type UI = {|
+isSliderOpen: boolean,
+isModalVisible: boolean,
+modalAction: string,
+modalPayload: Object,
|}
...
Run Code Online (Sandbox Code Playgroud)
我已将airbnb eslint配置添加到我的项目中,现在我得到:
type Props = {
logout: () => Action, //error ESLint 'Action' is not defined.(no-undef)
user: UserDetails, //error ESLint 'UserDetails' is not defined.(no-undef)
}
Run Code Online (Sandbox Code Playgroud)
它的纯粹的eslint错误.一切都配置得当,流动本身就很开心.
如何告诉eslint这些类型确实被声明为全局?或者我应该将它们添加到某个忽略列表中?
我有一个正在解析的 JSON 对象,我正在为输出编写测试,但我无法在运行时检查特定对象是否符合流类型。
const object = {/**/}
type SomeType = {
foo: string,
bar: bool,
baz: Object,
}
describe('object', () => {
describe('.subfield', () => {
it('conforms to SomeType', () => {
// Here I want to write an 'expect'
// that checks if object.subfield
// conforms to the SomeType flow type?
})
});
});
Run Code Online (Sandbox Code Playgroud)
有什么办法可以实现吗?
如果我正在使用流程.. https://flowtype.org/
// @flow
var foo = (str: string) => {
return str;
};
Run Code Online (Sandbox Code Playgroud)
和Eslint在一起,Eslint报告意外的令牌str: string.
有没有办法让Eslint忽略(或识别)流类型而不将它们报告为错误?
在Flow中,为什么要使用类而不是类型?
type Point = {x: number; y: number};
class Point = {x: number; y: number};
Run Code Online (Sandbox Code Playgroud) ...
[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow
flow/
...
Run Code Online (Sandbox Code Playgroud)
import { View } from 'react-native'; ---> produce: react-native. Required module not found.
...
Run Code Online (Sandbox Code Playgroud)
也许我的flowconfig的libs设置坏了?
- 反应原生0.42.3
- flow-bin 0.45.0
我有以下组件:
import { identity } from 'lodash';
export const Input = ({
onChange = identity
//etc.
}: {
onChange: Event<HTMLInputElement>,
}) => <Input onChange={onChange} />
Run Code Online (Sandbox Code Playgroud)
但是,当我运行流程时,我收到此错误:
onChange = identity,
^^^^^^^^^^^^^^^^^^^ default value. Expected polymorphic type instead of
onChange = identity,
^^^^^^^^ class type: Event
Run Code Online (Sandbox Code Playgroud)
我很困惑在哪里找到定义Event.
如果我看看facebook的dom类型:
我可以在这里看到具有类型的目标属性的事件.EventTarget
但从EventTarget 定义来看,我没有看到任何有价值的定义.
我没有看到定义合成事件,因此它具有HtmlInputElement类型的目标.
我正在使用flow来注释我的代码中的类型.
type Bar = 'One' | 'Two';
function foo(b: Bar) : boolean {
return b === 'Three';
}
Run Code Online (Sandbox Code Playgroud)
是否有任何方法可以教导flow报告警告或错误以与不匹配类型进行比较(string在我的情况下)?
编辑:所以似乎无法使用枚举.但是,由于这实际上是我遇到的错误,我想表达这一点,以便流程将帮助我标记这种情况.
有什么想法吗?
有没有办法将构造函数作为函数传递?
type foo =
| Foo of int
| Bar of int
let foo x = Foo x
let bar = fun x -> Bar x
Run Code Online (Sandbox Code Playgroud)
是否有功能的任何速记foo和bar?我想将构造函数作为函数传递,但编写起来似乎不实用fun x -> Bar x.
flowtype ×9
reactjs ×4
javascript ×3
eslint ×2
css-modules ×1
ocaml ×1
react-native ×1
sass ×1
types ×1
unit-testing ×1
webpack ×1