Questions tagged [flowtype]

Flow is a static type checker, designed to find type errors in JavaScript programs, created by Facebook.

What is Flow?

Flow is a static type checker, designed to find type errors in JavaScript programs.

The goal of Flow is to find errors in JavaScript code with little programmer effort. Flow relies heavily on type inference to find type errors even when the program has not been annotated - it precisely tracks the types of variables as they flow through the program.

At the same time, Flow is a gradual type system. Any parts of your program that are dynamic in nature can easily bypass the type checker, so you can mix statically typed code with dynamic code.

Flow also supports a highly expressive type language. Flow types can express much more fine-grained distinctions than traditional type systems. For example, Flow helps you catch errors involving null, unlike most type systems.

2301 questions
112
votes
9 answers

React eslint error missing in props validation

I have the next code, eslint throw: react/prop-types onClickOut; is missing in props validation react/prop-types children; is missing in props validation propTypes was defined but eslint does not recognize it. import React, { Component, PropTypes…
102
votes
4 answers

React PropTypes vs. Flow

PropTypes and Flow cover similar things but are using different approaches. PropTypes can give you warnings during runtime, which can be helpful to quickly find malformed responses coming from a server, etc. However, Flow seems to be the future and…
danielbuechele
  • 2,974
  • 2
  • 15
  • 28
62
votes
4 answers

React - using TypeScript vs Flow vs?

I'm currently learning React and I think I understand it pretty well. However, there's one thing that's been bothering me regarding development of robust React applications - what tools do developers use for static type checking? I really like…
Honza Kalfus
  • 3,987
  • 2
  • 24
  • 36
52
votes
5 answers

What's the right way to write Jest tests verified with Flow?

I imagine people commonly use Flow and Jest (and React) together, but Flow doesn't seem to know about Jest (or Jasmine) globals. When I add // @flow to my tests, I get Flow errors like this: src/__tests__/Thing-test.js:3 3:…
Trevor Robinson
  • 13,611
  • 5
  • 64
  • 66
46
votes
1 answer

How to type an exported RelayContainer

I'm trying to type (with flowtype) the components I'm enhancing with Relay.createContainer. I looked into the types exported by the "react-relay" package but ReactContainer doesn't seem to carry over Props. I experimented with RelayContainer,…
chollier
  • 892
  • 1
  • 7
  • 8
46
votes
3 answers

What is the difference between `mixed` and `any`?

The docs say: mixed: the "supertype" of all types. Any type can flow into a mixed. any: the "dynamic" type. Any type can flow into any, and vice-versa What would be a case where mixed and any cannot be used interchangeably?
Aton
  • 1,095
  • 8
  • 15
40
votes
3 answers

How to annotate a function with multiple possible call signatures in Flow?

In JavaScript, it's common to have a function that may be called in more than one way – e.g. with handful of positional arguments or a single options object or some combination of the two. I've been trying to work out how to annotate this. One way I…
callum
  • 26,180
  • 30
  • 91
  • 142
40
votes
4 answers

Flow (React Native) is giving me errors for using 'this.state'

Flow is giving me the following error whenever I try to use this.state in my code: object literal: This type is incompatible with undefined. Did you forget to declare type parameter State of identifier Component?: Here is the offending code…
Michael Campsall
  • 4,135
  • 9
  • 32
  • 49
37
votes
5 answers

Flow: Throws error Cannot resolve module "react-redux" even tho it's installed

Even tho module is installed and it exists, Flow cannot resolve it and throws error. See below: 1) Inside bash I ran flow and it throws error that module is not found user@pc:~/code/project$ flow Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈…
Kunok
  • 5,543
  • 8
  • 38
  • 72
36
votes
3 answers

Flow type, What does the `+` symbol mean in front a property?

I came across the following code written in js FlowType (I am interested to know the value of + in the context of FlowType not in general JS). Could you please explain me what does the + symbol mean in front of the property in the code below: …
GibboK
  • 64,078
  • 128
  • 380
  • 620
34
votes
4 answers

How can Flow be forced to cast a value to another type?

Is it possible to forcibly cast a variable in Flow? type StringOrNumber = string | number const foo: StringOrNumber = 'hello' // I look for something like `const bar:string = (string) foo` const bar: string = foo // fails const bar: string = (foo:…
czerny
  • 11,433
  • 12
  • 57
  • 80
31
votes
3 answers

How to correct flow warning: destructuring (Missing annotation)

I'm writing a small React Native app and I'm trying to use Flow, but I can't really get a proper tutorial about it anywhere. I keep getting the error: destructuring (Missing annotation) about the ({ station }) in the 1st line of this code: const…
jbssm
  • 5,976
  • 10
  • 45
  • 76
30
votes
2 answers

Flow: Create a flow type by extending another type

type someType = { keyOne: string, keyTwo: string, }; type someOtherType = { keyOne: string, keyTwo: string, keyThree: string, }; Both of these types are objects that contain keyOne and keyTwo, the only difference is the latter extends…
Jon Cursi
  • 2,837
  • 3
  • 19
  • 48
29
votes
3 answers

Flow “Required module not found” when importing a CSS file

When I try to import CSS via webpack(import (./index.css)) I'm getting this error: 3: import './index.css'; ^^^^^^^^^^^^^ ./index.css. Required module not found I have a structure like ComponentName→(index.js, index.css), so that each…
Roman Makarov
  • 313
  • 3
  • 8
29
votes
2 answers

Static type checking with immutable.js and Facebook flow

I've been using Immutable.js for my react app and I'm loving it. Facebook also released Flow. Flow would let me do very cool things like compile time validation of prop types. The problem is that my props are generally Immutable objects. Is there a…
1
2 3
99 100