小编Nat*_*ote的帖子

Flow(React Native)给出了使用'this.state'的错误

每当我尝试this.state在我的代码中使用时,Flow会给我以下错误:

object literal:此类型与undefined不兼容.您是否忘记声明State标识符的类型参数Component?:

这是有问题的代码(虽然它也发生在其他地方):

class ExpandingCell extends Component {
    constructor(props) {
    super(props);
    this.state = {
        isExpanded: false
    };
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激=)

reactjs flowtype react-native

39
推荐指数
2
解决办法
1万
查看次数

道具验证中缺少React eslint错误

我有下一个代码,eslint throw:

反应/道具类型onClickOut; 道具验证中缺少

反应/道具类型的孩子; 道具验证中缺少

propTypes 已定义但是eslint无法识别它.

import React, { Component, PropTypes } from 'react';

class IxClickOut extends Component {
  static propTypes = {
    children: PropTypes.any,
    onClickOut: PropTypes.func,
  };

 componentDidMount() {
    document.getElementById('app')
      .addEventListener('click', this.handleClick);
  }

  componentWillUnmount() {
    document.getElementById('app')
      .removeEventListener('click', this.handleClick);
  }

  handleClick = ({ target }: { target: EventTarget }) => {
    if (!this.containerRef.contains(target)) {
      this.props.onClickOut();
    }
  };

  containerRef: HTMLElement;

  render() {
    const { children, ...rest } = this.props;
    const filteredProps = _.omit(rest, 'onClickOut');

    return (
      <div
        {...filteredProps}
        ref={container …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs eslint flowtype

35
推荐指数
7
解决办法
6万
查看次数

如何纠正流量警告:解构(缺少注释)

我正在编写一个小的React Native应用程序,我正在尝试使用Flow,但我无法在任何地方获得适当的教程.

我一直收到错误:destructuring (Missing annotation)关于({ station })此代码的第1行:

const StationDetail = ({ station }) => {
  const {
    code,
    label,
  } = station;
Run Code Online (Sandbox Code Playgroud)

station是一个JSON响应codelabelstrings其内部JSON.

如何修复错误/警告?

javascript reactjs flowtype react-native

25
推荐指数
2
解决办法
1万
查看次数

在Flow中使用星号(*)类型有什么用,在TypeScript中有什么用呢?

首先,我大多熟悉TypeScript.Flow在许多方面看起来与TS非常相似,但我最近偶然发现了一个星号(*)类型.起初,我认为它是"any"的同义词,但是现在,在阅读了Flow的一些发行说明后,我发现它并非如此.我浏览了所有官方文档,但未能找到"*"的任何用法.

那么,它是什么以及何时使用它?但是,什么是TypeScript中的直接等价物?

javascript types flowtype

23
推荐指数
1
解决办法
3839
查看次数

StyleSheet.create"未被流程覆盖"

我在一个带有核素的反应原生项目中使用流量0.42.0.

使用默认项目,我收到以下消息:

在此输入图像描述

以下错误:

> flow check
index.ios.js:40
 40:             <View style={style.container}>
                                    ^^^^^^^^^ property `container`. Property cannot be accessed on possibly undefined value
 40:             <View style={style.container}>
                              ^^^^^ undefined

index.ios.js:40
 40:             <View style={style.container}>
                                    ^^^^^^^^^ property `container`. Property not found in
 40:             <View style={style.container}>
                              ^^^^^ Array

index.ios.js:41
 41:                 <Text style={style.welcome}>
                                        ^^^^^^^ property `welcome`. Property cannot be accessed on possibly undefined value
 41:                 <Text style={style.welcome}>
                                  ^^^^^ undefined

index.ios.js:41
 41:                 <Text style={style.welcome}>
                                        ^^^^^^^ property `welcome`. Property not found in
 41:                 <Text style={style.welcome}>
                                  ^^^^^ Array

index.ios.js:44
 44: …
Run Code Online (Sandbox Code Playgroud)

css flowtype react-native

22
推荐指数
1
解决办法
1224
查看次数

如何使用Flow键入默认导出?

如何使用Flow键入默认导出?Flow有办法实现这个目标吗?

期望的结果:

// index.js
type complexThing = {
  a: string
}
type Thing = {
  x: number,
  y: boolean,
  z: complexThing
}

export default {
 x: 0,
 y: true,
 z: {a: 'hello'}
} : Thing // this says my default export is a Thing
Run Code Online (Sandbox Code Playgroud)

可接受的替代方案:

或者,我不介意内联键入每个对象属性,但我认为这在语法上是不可能的:

export default {
 // I don't know how to add type signatures here
 x: 0, // number
 y: true, // boolean
 z: {a: 'hello'} // complexThing
}
Run Code Online (Sandbox Code Playgroud)

不是我想要的:

希望做的是存储变量只是对流动键入:

// index.js
type …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 flowtype

14
推荐指数
1
解决办法
3255
查看次数

流:动态生成字符串联合类型?

假设我有一个流类型Suit,我想把它组成另一个叫做的类型Card.

// types.js

type Suit =
  | "Diamonds"
  | "Clubs"
  | "Hearts"
  | "Spades";


type Card = {
  ...
  suit: Suit,
  ...
}
Run Code Online (Sandbox Code Playgroud)

而不是直接在suit.js中对Suit字符串进行硬编码,是否可以Suit基于JavaScript原语(数组)动态生成类型?说...

// constants.js

const SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades'];
Run Code Online (Sandbox Code Playgroud)

通过这种方式,套装只能定义一次,并且可以在JavaScript构造中定义,以便在应用程序的其他部分中重复使用.例如,应用程序中其他位置需要访问所有可用套装的组件:

// component.js

SUITS.map((suit: Suit): void => { ... });
Run Code Online (Sandbox Code Playgroud)

javascript types flowtype

14
推荐指数
1
解决办法
741
查看次数

反应本机和流错误消息

嗨,我试图用React Native做一些你好的世界.我创建项目'react-native init'更改'.flowconfig'中的流版本.

跑流,它给了我153个错误,在node_modules文件夹中 node_modules/react-native/Libraries

有没有人遇到同样的问题?

flowtype react-native

12
推荐指数
1
解决办法
3363
查看次数

创建OCaml库

我正在尝试创建一个可以在其他OCaml项目中使用的库,我完全迷失了.

我目前正在使用ocamlbuild哪个非常适合吐出可执行文件,但我不知道如何从中获取库.

我发现了-a选项ocamlopt,ocamlc但我不确定如何使用它.我发现的文档(例如,这里)似乎假设了一些预先存在的知识.我甚至都不知道.a文件是什么.运行之后,我需要构建一个依赖于此库的项目的输出文件?我是否需要mli文件以便应用程序知道库代码的签名,或者以某种方式包含在输出中?此外,能够将所有文件打包在一起会很好,类似于Java的.jar文件.

在任何情况下,我都希望能ocamlbuild为我做所有这些,因为如果我必须调用,ocamlopt -a我将不得不手动指定依赖项或破解脚本ocamldep- ocamlbuild应该修复的东西.但是,我不知道如何告诉它建立一个库.

如果有必要,我愿意使用绿洲或OPAM或其他东西,但我想首先使用基本工具学习如何做到这一点.

ocaml ocamlbuild

9
推荐指数
1
解决办法
977
查看次数

使用.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
查看次数