小编Nat*_*ote的帖子

使用.scss文件找不到流模块

我有一个文件使用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但它确实没有任何解决方案.

有没有人找到解决这个问题的方法?

sass webpack flowtype css-modules

8
推荐指数
4
解决办法
3250
查看次数

流程:如何键入注释本地/全局变量?

如果我的代码中有process.browser变量,我该如何对其进行注释?

reactjs flowtype

8
推荐指数
1
解决办法
3861
查看次数

ESLint报告流类型全局类型的no-undef错误

我有定义的全局类型/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这些类型确实被声明为全局?或者我应该将它们添加到某个忽略列表中?

reactjs eslint flowtype eslint-config-airbnb

8
推荐指数
1
解决办法
2420
查看次数

你能在运行时检查一个对象是否符合 Flow 类型吗?

我有一个正在解析的 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)

有什么办法可以实现吗?

javascript unit-testing flowtype

7
推荐指数
1
解决办法
6354
查看次数

Eslint将流类型报告为语法错误

如果我正在使用流程.. https://flowtype.org/

// @flow
var foo = (str: string) => {
  return str;
};
Run Code Online (Sandbox Code Playgroud)

和Eslint在一起,Eslint报告意外的令牌str: string.

有没有办法让Eslint忽略(或识别)流类型而不将它们报告为错误?

javascript eslint flowtype

7
推荐指数
1
解决办法
4052
查看次数

Flow中的class vs type

在Flow中,为什么要使用类而不是类型?

type Point = {x: number; y: number};
class Point = {x: number; y: number};
Run Code Online (Sandbox Code Playgroud)

flowtype

7
推荐指数
1
解决办法
3049
查看次数

[Flow] react-native:找不到所需的模块

.flowconfig

...
[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow
flow/
...
Run Code Online (Sandbox Code Playgroud)

index.js

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

reactjs flowtype react-native

7
推荐指数
1
解决办法
1856
查看次数

为onChange等提供流注释的类型

我有以下组件:

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类型的目标.

reactjs flowtype

7
推荐指数
3
解决办法
3166
查看次数

比较Flow中的枚举值

我正在使用flow来注释我的代码中的类型.

type Bar = 'One' | 'Two';
function foo(b: Bar) : boolean {
  return b === 'Three';
}
Run Code Online (Sandbox Code Playgroud)

是否有任何方法可以教导flow报告警告或错误以与不匹配类型进行比较(string在我的情况下)?

这是测试的例子

编辑:所以似乎无法使用枚举.但是,由于这实际上是我遇到的错误,我想表达这一点,以便流程将帮助我标记这种情况.

有什么想法吗?

javascript types flowtype

6
推荐指数
1
解决办法
344
查看次数

构造函数的简写

有没有办法将构造函数作为函数传递?

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)

是否有功能的任何速记foobar?我想将构造函数作为函数传递,但编写起来似乎不实用fun x -> Bar x.

ocaml

5
推荐指数
1
解决办法
663
查看次数