Questions tagged [flowtype]

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

flowtype
Filter by
Sorted by
Tagged with
0 votes
1 answer
9 views

Type-cast to type-alias in inline comment type (Flow)

I have a vanilla JavaScript file using Flow, like so: // @flow /*:: type orderType = number; */ let ot = 0 /*:: as orderType */; but I get error Invalid type cast syntax. Use the form (<expr>: ...
Olle Härstedt's user avatar
0 votes
1 answer
26 views

Can I use $ReadOnly on inline type declarations with Flow?

Say I have an inline type like class Tmp { #myreadonlystring /*:string*/ = "Some string"; } Can I use the utility type $ReadOnly somehow here? I tried #myreadonlystring /*:$ReadOnly<...
Olle Härstedt's user avatar
0 votes
1 answer
14 views

Can Flow limit strings to a number of alternatives, similar to enum?

In some legacy code, strings are used as enums, and should be limited to a certain number of available values. Is this possible to do with Flow?
Olle Härstedt's user avatar
1 vote
0 answers
17 views

How can I configure Flow to show all errors via .flowconfig?

I know I can use --show-all-errors from CLI, but to make it work with ALE and Neovim, I'd like to add this option in .flowconfig file, too. Possible? Related ALE configuration for Flow: https://github....
Olle Härstedt's user avatar
1 vote
0 answers
39 views

Missing imports not detected

I'm following this guide https://flow.org/en/docs/tools/eslint/ to enable eslint to detect flow related issues, however it seems that while it correctly checks for issues related to flow, it stops ...
Barbaldo's user avatar
1 vote
1 answer
163 views

Why does Flow allow mismatched type comparisons when one operand is an array access?

The two comparisons below seem equivalent, but only one gets a type error (playground): function test(arr: string[]) { const el = arr[0]; if (el === 2) { } // Error here if (arr[...
Ryan Cavanaugh's user avatar
0 votes
1 answer
39 views

Missing-this-annot together with jQuery each()

Pretty basic usage of jQuery that seems not easy to give a proper type in Flow inline? jQuery(`.someclass`).each(function(j, el) { ... } Any tips? I've tried to add /*this: Object*/ or such, but ...
Olle Härstedt's user avatar
0 votes
1 answer
328 views

Flow error property is missing in object literal [1] when using reduce to create a dictionary from an array

I'm trying to use reduce to create a dictionary from an array. However I run into a flow error property is missing in object literal [1] when using reduce to create a dictionary from an array. This ...
Jay Hu's user avatar
  • 83
1 vote
1 answer
101 views

How to get Union type from an array of objects in Flow?

For instance, imagine having the following list of items: const items = [ { key: "amalgama" }, { key: "torin" }, { key: "mascarpone" ...
ShiiRochi's user avatar
2 votes
0 answers
35 views

Flow type grandchild inheritance issues

I'm curious as to why this inheritance model succeeds between a base and child, but fails between a child and grandchild. I'm sure there is something I've missed here. The error would make sense to me,...
anson's user avatar
  • 4,154
1 vote
1 answer
305 views

In Flow, what does Missing an annotation on implicit `this` parameter of function. [missing-this-annot] mean?

I have a Javascript file that looks like this: // @flow /** * My database module. * * Interact with the database. */ 'use strict'; module.exports = { /** Mockable wrapper around mongoose. */ ...
alberto56's user avatar
  • 3,094
-1 votes
1 answer
67 views

Flow type. What is the difference between type {} & {||}

I dont know what is the exact differences. I want to know what is the differences
brainli's user avatar
  • 462
1 vote
0 answers
33 views

Flowtype libdefs -- How to export a class definition from one module and extend it in another?

The project I'm working on uses some 3rd-party libraries in which a main module defines classes that are imported and extended by other, associated modules. In my case the main module is three.js, a ...
Ray Ellis's user avatar
1 vote
1 answer
49 views

Are { [string]: string } and { [string]: (string | number} } incompatible is right?

string and string | number are compatible, but { [string]: string } and { [string]: (string | number} } are incompatible. Am i doing something wrong? https://flow.org/try/#...
Shintaro Abe's user avatar
0 votes
1 answer
36 views

Why are these matching unions non-equivalent in Flow?

Link to Flow Try From this test it looks like Flow can only check union equivalence at the top-level. I would like to know way to fix this error, preferably without a switch statement with every case ...
Athe's user avatar
  • 65
0 votes
0 answers
28 views

Type accepting parameters

I'm super new to TypeScript & Flow, so maybe I'm asking the wrong question. Here's what I basically want. I have existing code such as follows: export type MyCustomType = { +setCounterActive: ...
nalabof679's user avatar
1 vote
0 answers
197 views

What is the equivalent of `never` TypeScript type in Flow?

What is the equivalent of never TypeScript type in Flow? I am working on a project which uses flow for type checking. There I have to define a throwing function. In Typescript we can use never type ...
Dhruv Tailor's user avatar
  • 2,681
0 votes
1 answer
94 views

How to declare flow type for named exports?

I have a file with a default export and some other named exports. module.exports = function1; exports.names= []; exports.getStrings = getStrings; function1 and getString functions are defined. ...
Dhruv Tailor's user avatar
  • 2,681
43 votes
4 answers
35k views

Cannot assign to 'current' because it is a read-only property

I am trying to have a useRef obj to be either null or a function here is code snippet import "./styles.css"; import { useState, useRef, useEffect } from "react"; export default ...
Sean Liu's user avatar
  • 1,219
0 votes
1 answer
41 views

Excessive typing for class-based React component

Flow version: 0.186.0 There's simple React component //@flow import * as React from 'react'; export default class App extends React.Component<{}> { onClick = (event: SyntheticEvent<...
Nick's user avatar
  • 1
2 votes
1 answer
86 views

VS Code Flow-Language-Support Failed to Start: Couldn't find version of '../node_modules/flow-bin/flow-linux64-v0.174.1/flow'

So I'm using VSCode coupled with the VSCode remote server sitting on my VM. I'm trying to use the Flow-Language-Support plugin, but I get the following error. Failed to Start: Couldn't find version of ...
Christopher Phifer's user avatar
0 votes
1 answer
33 views

Should Flow be marking this type as potentially `string`?

To me it should be a union of the string literals and not also string type UnionType = {|type: "A"|} | {|type: "B"|} | {|type: "C"|} const objectB: UnionType = {type: &...
Athe's user avatar
  • 65
2 votes
2 answers
489 views

Why flow type casting not working for string literal as expected

For the below example why type casting is not working in Flowtypes? What should be an ideal way of doing it? type typeA = { name: 'ben' | 'ken', }; type typeB = { name: string, }; const objA: ...
bhushan laware's user avatar
1 vote
1 answer
278 views

Flow Enums correctly parsed but not transformed

In my React app, I'm trying to migrate from my "old school" JS enums to Flow Enums: https://flow.org/en/docs/enums/ (I think) I've done everything listed here: https://flow.org/en/docs/enums/...
Rodolphe's user avatar
  • 1,722
0 votes
1 answer
65 views

What is the type of this function argument?

How can i write a type validation for my second method (i m struggling with the argument v as it need's to inherit it's type from values in the Array lo.foreEach = ([1,{},true],(v,i,list))=>{/** ...
Tarik Gadoumi's user avatar
0 votes
1 answer
34 views

Why doesn't Flow understand this simple logic?

I noticed that my project doesn't label a as undefined in this context. Could anyone help me to understand? As it seems very simple to me. In this case a can be hard typed as a defined string without ...
Athe's user avatar
  • 65
1 vote
1 answer
137 views

Why is flow complaining that my variable is not a string?

My code is as follows (I believe this is mostly a typing issue so I don't think the actual code for downloading is relevant here): ... TokenService.getToken(id).then(result => { const { read } = ...
user avatar
1 vote
1 answer
327 views

Typing React Context with Flow

We're using Flow in our project and I'm chasing my tail on this one. Am using React Context to store a user's favourite assets, this will be used in multiple places. I can't get Flow happy with React ...
cortexlock's user avatar
  • 1,456
0 votes
1 answer
94 views

Flow JS Union types and callbacks

I have a flow curiosity regarding union types and callbacks, where it seems logically to me that the error cannot happen given the circumstances. I'm wondering if I'm having a brainfart, if flow just ...
anson's user avatar
  • 4,154
1 vote
0 answers
83 views

Flow does not recognize a refinement of disjoint union of tuples

Is there a way to refine a union of tuples correctly in flow? I see examples for object types in docs but looks like it has a difference for arrays and I don't see any clue for that case. I have this ...
Max Sinev's user avatar
  • 5,954
2 votes
1 answer
1k views

Unexpected token, expected {

In my .flowconfig i've added enums=true under options : [options] enums=true however i'm getting this error, and app created with createreactapp doesnt wanna compile this enum. Unexpected token, ...
Mladen Oršolić's user avatar
1 vote
0 answers
166 views

Flow-type WebStorm how to show type hints on mouse hover over object variables

In flow-type, on mouse hover over variable of any type object we do not see type hints: However, WebStorm does see the type is: Searched well and played with the setting, but could not find how to ...
Eliav Louski's user avatar
  • 4,367
0 votes
2 answers
2k views

cannot find module in index.js

hi I have this error while trying to import components (im using flow type) This is my ReloadScreenPayLater.component.js /** * Reload Screen Component * @param {Props} onReload - reload ...
QrQr's user avatar
  • 161
0 votes
1 answer
169 views

Flow to Typescript

I now have flow type code like this export interface NodeBase { start: number; end: number; } export type Node = NodeBase & { [key: string]: any }; Then I used this in the function ...
LianwenWu's user avatar
0 votes
1 answer
196 views

"Expected an arrow function after this type parameter declaration" error

I got this error while running yarn start: $ yarn start yarn run v1.22.17 $ run-s build exec $ babel src/ -d lib/ SyntaxError: .../src/App.js: Expected an arrow function after this type parameter ...
injoy's user avatar
  • 4,263
1 vote
0 answers
19 views

Why can't I use an Intersection type here but spreading one type into another works?

Today I found out that I can do the latter here, but not the former, and I can't figure out why. This does NOT work: type User = {| id: number |} type ExternalUser = User & {| externalUser: ...
S. Smith's user avatar
2 votes
0 answers
18 views

Properly typing generic object property access

I have a bit of JS that I've removed all of the unimportant bits from, and I'm trying to add Flow types to it: function doStuff(key, data, callback) { callback(data[key]); } In this case, data is a ...
anthony's user avatar
  • 21
0 votes
0 answers
287 views

In flow, can you define an exact object type, using string types to define the keys

In flow, is it possible to define an exact object type, where the keys are also types? In typescript you can accomplish this using strings, like... export const userSettingsId = 'user-settings'; ...
Nizmox's user avatar
  • 17
0 votes
1 answer
634 views

Return type for asynchronous function

I have this code that is a simple implementation of async/await while doing ajax call export const getExternalResource = async (): Promise|String|null => { return new Promise(async (resolve, ...
Ivan Hanák's user avatar
  • 2,254
1 vote
1 answer
1k views

Is it's possible use material-ui codemod v5 in project with flow types

I want migrate from material-ui v4 to v5. When i run codemode with: npx @mui/codemod v5.0.0/preset-safe . it's not working, in files where flowjs types declared as: (all files in my case) type Props =...
Yuri Palienko's user avatar
0 votes
1 answer
79 views

Is it possible to detect missing Object.freeze() with Flow?

Flow has $ReadOnly utility type [1] that represents a read-only view of T. Unfortunately, as Flow allows to assign a mutable T to its read-only version, it cannot be used to model the usage of Object....
Igor Bukanov's user avatar
  • 4,874
3 votes
0 answers
245 views

Flow enum is not defined

I'm trying to use flow enums. Here is what I have done so far: I installed babel-plugin-transform-flow-enums as a dev dependency. I installed flow-enums-runtime as a regular dependency. I loaded the ...
deadalnix's user avatar
  • 2,267
0 votes
1 answer
288 views

How do I fix this flow < 0.114 error with react-native > 0.64?

I'm upgrading this react-native 0.64 to 0.67 project. The project uses flow as its typechecking language. We are also migrating it to typescript, but that's not the scope of the current error and we ...
ofundefined's user avatar
  • 3,002
2 votes
0 answers
301 views

How to get "property missing" error messages with empty (and thus unsealed) objects

So, I have an API that takes an options object, something like this: type Options = { pos: number }; function doTheThing(options: Options) { } Now, if I call this with any of the below, I get a nice ...
Francisco Ryan Tolmasky I's user avatar
2 votes
0 answers
3k views

Failed to load plugin 'flowtype' declared in '.eslintrc.json': Cannot find module 'eslint/use-at-your'

I start my project at command -> Create-react-app Yesterday, when I opened my project in WebStorm, I saw the following I tried to change eslint config, but it's doesn't works. I don't know how it ...
Vasily Yankovsky's user avatar
1 vote
2 answers
661 views

Unable to resolve react-bootstrap modules flow error

I am setting up flow static type checking for my react project (pretty new to it). I also installed react UI library, React-Bootstrap. This is how my current setup is: .flowconfig [ignore] .*/build/.* ...
program_bumble_bee's user avatar
30 votes
11 answers
45k views

Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot find module 'eslint/use-at-your-own-risk'

I created a new React project with create-react-app. In the terminal npm start. Instantly get this error Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot ...
Matt's user avatar
  • 34.3k
0 votes
1 answer
69 views

Flow React HOC typing (without HOC)

I need to type HOC for my component (and that was asked millions of times). But I need to do something opposite to the typical withSomething injection. I need to add an extra property to my outer ...
Roman Kurbatov's user avatar
0 votes
0 answers
74 views

Why does default export add any type in Flow?

Currently trying to convert a part of the codebase into Flow. While I was tackling with API calls, I have created a hook to abstract the functionality. However when I tried to import it, the function ...
Muhammed Bera Koç's user avatar
3 votes
1 answer
77 views

Function overloading with generic types in Flow

I have a component <ButtonGroup value={value} options={[1, 2, 3, 4, 5, 6].map((x) => { return { label: x, value: x }; })} /> I am using Flow for type checking and want to know, ...
nikkegg's user avatar
  • 31

1
2 3 4 5
48