Questions tagged [flowtype]

1

votes
0

answer
6

Views

Composable and positive contracts in Flow

I'm having a problem with Flow where a given implemented type is restricting my object API by asking me to use only properties that are declared on the type instead of asking me to declare all the type's properties. I'm new to Flow so I'm probably making some basic mistake and stuff. Anyway, I have...
Henrique Guerra
1

votes
1

answer
400

Views

Custom type is incompatible with mixed

The problem can be demo'd here I want to define a function that can take an array of mixed types: function foo(x: Array): string { // ... do something } Then I try to call it with an array off some custom object type: type Thing = { id: string } let array : Array = [{id: 'hello'}]; foo(array); ... a...
1

votes
2

answer
1.3k

Views

Flow generates many errors for new project

Flow seems to generate a lot of errors on a new project. What am I doing wrong ? What I did: Created a new React Native project using react-native init FlowProject Followed the set-up for Flow with yarn and Babel yarn add --dev babel-cli babel-preset-flow yarn add --dev flow-bin Ran yarn run flow (....
Julian Honma
1

votes
2

answer
102

Views

Getting React flow error: module is not a polymorphic type. How to extend a class?

I am trying to extend my existing layout to basically override the method renderHeader() but flow doesn't like it: module ./Layout [1] is not a polymorphic type. how do I fix this? here is a class I am trying to extend (it's not abstract): Layout.js //@flow import * as React from 'react'; import H...
jeff
1

votes
0

answer
94

Views

Flow cannot decide which case to select in intersection type when iterating over Immutable.Record

// @flow import type {RecordOf} from 'immutable'; function foo(state: RecordOf) { for (let [key, value] of state) { console.log(key, value); } } In the code above, the for...of loop causes a flow type error: $Iterable. Could not decide which case to select intersection type. I assume that is becaus...
ojii
1

votes
1

answer
57

Views

Unexpected flow error when determining if object has attributes

Given the following type: /* @flow */ type Vehicle = { make?: string, model?: string, }; const vehicle: Vehicle = { make: 'Ford', model: 'Focus', }; If I wanted to make sure that the make and model attributes were defined before using them I would expect the following to work: const hasAttributes =...
jkimbo
1

votes
0

answer
347

Views

How to create generic class extending React.Component?

I'm using Flow.js in my React application. Within it I've created custom Form component extending React.Component: import * as React from 'react' class Form extends React.Component { // utils for form-handling logic in my form components } Here are my form types: export type ValidationResult = Array...
Ralfp
1

votes
0

answer
52

Views

How to recursively type a mirroring function

Say we've got a function, keyMirror that takes an Object with arbitrary values and returns another object with values that match the keys. For example: Input: { KEY_ONE: '', KEY_TWO: '', } Output: { KEY_ONE: 'KEY_ONE', KEY_TWO: 'KEY_TWO', } Using $ObjMapi, typing this would be fairly trivial: type k...
Ross Solomon
1

votes
0

answer
32

Views

How to required members of a class by flow

I usually define required members of a class by flow like the below. // @flow type Required = { firstName: string, lastName: string } class User { firstName: string lastName: string middleName: string age: number constructor(params: Required) { this.firstName= params.firstName this.lastName= par...
Nigiri
1

votes
1

answer
88

Views

FlowType Does Not Recognize ES6 Function Import

I'm looking into using Flow on a project for type checking. To that end, I've made a simple flow project based on the Flow tutorial listed on their website. I have two files. One exports a couple of functions: // @flow export function add(num1: number, num2: number): number { return num1 + num2; } e...
Nathan G
1

votes
1

answer
310

Views

flow: cast mixed type to an array of shape

I need to cast a mixed type to a shaped array in flow. Tryflow link. type aShapedArray = Array; //externally defined type const transform = ():mixed => [{a: 'hello'}]; const b = transform(); if (Array.isArray(b)) { const a: aShapedArray = b; } The error is 9: const a: aShapedArray = b; ^ array. Ha...
Diana Suvorova
1

votes
1

answer
48

Views

Why does this code typecheck correctly with flow

I have a function returning a less specific type, being called by something returning a more specific type. See the link here tryflow ` /*flow*/ type SimpleObject = {[string]: number} type Spc = {s: number} function foo(): SimpleObject { return {i: 10}; } function bar(): Spc { return foo(); } `
Vishnu
1

votes
0

answer
184

Views

Flow type extends generic type and private member with symbol

I'm trying to add flow type to my code and I have some issue with Generic types, I want to write something like this T extends Object to be able to use obj.constructor.name and so on. Also, I have issue with Symbol in class please see following code const postProcessors = new Symbol('postProcessors'...
ashmna
1

votes
0

answer
54

Views

Flow unable to infer union type with computed object keys

So I have a union type, EduType, defined as follows: export type EduType = | { level: string } | { program: string } | { level: string, program: string } and a function that returns a function which expects an EduType, defined as follows updateEduSelects(which: 'level' | 'program') { return (_, __,...
JohnTheScout
1

votes
2

answer
33

Views

How do I write the flow definition for a function where the input is an object, and the output is mutated

How do I write the flow definition for a function where the input is an object exact type, and the output is the object mutated with an added property? Here is an example I have copy pasted the code from the example below in case the link expires. /* @flow */ // README: select version 0.56.0 // this...
davidtingsu
1

votes
0

answer
91

Views

How to declare flow types for REST API

=====EDIT===== Thanks to @kalley I updated my declaration file and made a bit of progress. I don't have a linting error anymore, but I still can't get the type to be recognizes where I import them. I updated the content of the files above =====end EDIT===== I'm trying to create flow type for a REST...
otusweb
1

votes
1

answer
53

Views

Flow: Inference error in for-of loop

I have a code this is trying to validate object with attributes id and _name for specified type. Attribute id should be a number and name should be a string as declared in FooT type. function number(value: mixed): number { if (typeof value === 'number') return value throw new TypeError('number requi...
gecko
1

votes
0

answer
85

Views

How to add type definitions to composed enhancers with Flow?

Flow is driving me crazy. Even though it's really comfortable to use with some sort of 'basic' code, it's hard to type when making use of HOCs (as you can see in some of my last questions ...). So, I've got a component which: needs an prop from the parent component (activeProject) connects to a Redu...
Slevin
1

votes
1

answer
79

Views

Getting flow to pick from a union of tuples

I have a function that returns a union of tuples and it seems like flow is unable to pick one of these tuples no matter what I do. Example (try flow link): declare function genNumber(): [Error, null] | [null, number]; const [err, num] = genNumber(); if (err) { throw err; } // num should now be a nu...
Mark Kahn
1

votes
0

answer
59

Views

Forwarding Props to React Component flow

The basic idea of forwarding props is that I want to enhance an element, by composing it. E.g. class MyButton extends Component { render() { const { busy, children, ...props } = this.props return { busy ? 'busy' : children } } } Here I can add an extra property (busy) to the button element, but sti...
Arwed Mett
1

votes
1

answer
75

Views

react and flow: import Node type and PureComponent in one line

How to import Node (type used by flow), and PureComponent in one line only for code purity. Lines below don't work: import type { Node }, { PureComponent } from 'react'; // or import type { Node, PureComponent } from 'react'; Note: I actually use this /* @flow */ import { PureComponent } from 'react...
Made in Moon
1

votes
1

answer
192

Views

Flow typing with bindActionCreators is not working on mapDispatchToProps

Here is my dispatch props definition: type DispatchProps = { selectRow: (index: number) => void, loadData: (fetchArgs: FetchArgs) => void, }; // This works const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ selectRow: (selectedRowIndex: number) => dispatch(actions.selectRow(selecte...
1

votes
0

answer
29

Views

Flow: Internal Error: Unexpected class static type: ObjProtoT

I try to generate flow typings for my small library written with flow, but I have this error: -> % flow gen-flow-files src --out-dir dist Found 14 files, generating libdefs... Error: Failure('./src/types.js: Failure(\'Internal Error: Unexpected class static type: ObjProtoT\')') If I run only check:...
Vladislav Orlov
1

votes
0

answer
78

Views

Uncaught error: Cannot find module “./src/module.js” with importing flow type module

The module.js is where my flow type module is, I'm trying to apply the code in my form.js by importing it from the node module 'module.js' but shows the error Uncaught error: Cannot find module './src/module.js'. I'm not sure where the error is coming from since that's the only error I got. module....
Jackson Tiu
1

votes
2

answer
302

Views

Installing Flow with a new React Native App

I am trying to get started with Flow with React Native app but I always get an error that the node_module is not properly configured with Flow. Ultimate in the .flowconfig I added a line to ignore everything under the node_module director but that gives me an error that it cannot find 'react nat...
Yahoo
1

votes
1

answer
50

Views

Flow does not report the correct type for a variable without @flow

I have a file with the following three lines. // var g1 = navigator.geolocation; g1.getCurrentPosition(position => {}, () => {}); Flow reports the type of g1 as: '2:5-6: any' when I ran dump-types command. When I add @flow directive into the file as the following: //@flow var g1 = navigator.geolocat...
Lou
1

votes
0

answer
55

Views

flow is unable to decide which case to select on union type

When i try union tuple have array some length I get the error Look at this work example where each type have different length. Example. (UPD: change flow version to 0.71) But when I try add type with some length flow can not resolve it. Example. type Step = T | [T] | [T, Object]; type S3 = [Step] ty...
Max Vem
1

votes
1

answer
115

Views

Flow cannot find schema property on knex

I'm working on a project which uses knex for database connections. I'm also using flow for typings. I'm attempting to connect to the database as follows: const db = knex({ client: 'mysql', connection: { host: containerized() ? 'database' : process.env.DB_URL || 'localhost', user: process.env.DB_USER...
Gregory Sims
1

votes
0

answer
86

Views

Disjoint unions in React.Component props

I recently stumbled across the disjoint unions from flow-js (https://flow.org/en/docs/types/unions/#disjoint-unions-) and tried to use them in my React.Component props. The base idea was that I have a set of props that always needs to be set and according to a property, some other field also needs t...
kr1x
1

votes
0

answer
73

Views

How to annotate generator with Flow?

I want to annotate generators with Flow like this: // @flow function* generator(): Generator { yield 1; yield 2; yield 3; } But Flow coverage rate doesn't become 100%. 3 'yield's are colored red. $ npx flow coverage --color generator.js // @flow function* generator(): Generator { yield 1; yield 2; y...
K.Ohara
1

votes
0

answer
53

Views

Flow annotation for iterable and async iterable objects?

I have a function foo that returns an object that can be iterated: const foo = () => ({ [Symbol.iterator]: function * () { yield * [ 1, 2, 3 ]; }, }); for (const x of foo()) { console.log(x); } // 1 // 2 // 3 Now I would like to annotate foo with Flow type definitions. But what do these look like...
sdgfsdh
1

votes
0

answer
47

Views

disable properties through generic parameters

Suppose you have a type like: type T = {| p: E |} Is there a way of providing a specific argument for E that removes the property p. My intuition was that void should be do exactly that but when I try const a: T = {} flow complains that p is not defined. It works only when I specifically assign p: c...
Philipp Dargel
1

votes
1

answer
57

Views

How to describe a proxy object type that always returns a predefined value type?

I currently have the following helper function to create a getter function that always returns result or throws an error: // @flow type StrictMapType = { [key: string]: V }; const createStrictMap = (map: StrictMapType): (name: string) => V => { return (name) => { if (name in map) { return map[name];...
Gajus
1

votes
0

answer
331

Views

How to install Flow (code suggestions) for React Native in VS Code?

I'm struggling in setting up flow on my VScode for react native, it seems hard to find a guide for a proper way to install it, need help please!
Leon Chow
1

votes
1

answer
48

Views

Flowtype - encode a type refinement in another type

In Flow, with a disjoint union type I can use type refinement to selectively target a subset of the union based on a certain property. That's great, if I want to put all my code in a one switch statement. If I want to split my code up into functions, however, I don't know how to 'encode' the type re...
davnicwil
1

votes
1

answer
76

Views

Optional object prop fails to read when specified the key returned from a function

Here's the gist of the code, and you can try it here. why's this failing? type Stuff = { prop?: {[string]: string} } const a: Stuff = {} const b: Stuff = { prop: {'key': 'value'} } function getKey(): string { return 'somekey' } const key: string = 'somekey' b.prop && b.prop[key] b.prop && b.prop[get...
Ryo
1

votes
0

answer
43

Views

In vim, how can I write a line to top of buffer on open, and remove that line on save?

I am using vim as my text editor for programming in react/javascript, and trying to use flow for static type checking. In my .flowconfig, I have all=true, meaning I would like to have flow type checking on all .js files without requiring a comment at the top of each file. I have the vim plugin ale s...
Danny Harding
1

votes
1

answer
63

Views

Flowtype generic function with different parameters

I'm struggling with flowtype declaration for a generic function with different pairs of parameters. My goal is to have a function which return an object of certain union type depending on input parameters. I'm having a big load of messages that i want to type (for this example i'm using only two) ty...
vietzky
1

votes
0

answer
516

Views

type vs interface indexer property in flow

Could someone explain to me what is the difference between type vs interface in flow? I have been reading online but could not find an answer. Here is the code: https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVBLAdgFwKYBOUAhgMZ5gCyeOxAJsbWAN6phgDWeAngFxgBnHAWwBzANxswAN2IwArnn7Es3SQF902fETIVqtBrQDyAIwBWL...
leogoesger
1

votes
0

answer
79

Views

does anyone have a real web-project working with Flow types?

I have a simple web-project with React, webpac-dev-server, eslint, prettier, jest wich is not acceptably working with Flow. Any changes make Flow to caclculate new decision during 4-5 minutes!!!! I made configurations for WebStorm and VSCode - situation with Flow in VSCode is better but not enough f...
Vadim

View additional questions