Questions tagged [flowtype]
Flow is a static type checker, designed to find type errors in JavaScript programs, created by Facebook.
2,377
questions
1
vote
0
answers
21
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 ...
1
vote
1
answer
150
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[...
0
votes
1
answer
37
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 ...
0
votes
1
answer
228
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 ...
1
vote
1
answer
89
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"
...
2
votes
0
answers
33
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,...
1
vote
1
answer
237
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. */
...
-1
votes
1
answer
50
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
1
vote
0
answers
31
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 ...
1
vote
1
answer
43
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/#...
0
votes
1
answer
35
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 ...
0
votes
0
answers
25
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: ...
0
votes
0
answers
168
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 ...
0
votes
1
answer
81
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.
...
24
votes
4
answers
20k
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 ...
0
votes
1
answer
39
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<...
2
votes
1
answer
74
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 ...
0
votes
1
answer
31
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: &...
2
votes
2
answers
447
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: ...
1
vote
1
answer
234
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/...
0
votes
1
answer
63
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))=>{/** ...
0
votes
1
answer
32
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 ...
1
vote
1
answer
87
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 } = ...
1
vote
1
answer
265
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 ...
0
votes
1
answer
88
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 ...
1
vote
0
answers
75
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 ...
2
votes
1
answer
855
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, ...
1
vote
0
answers
147
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 ...
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 ...
0
votes
1
answer
151
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
...
0
votes
1
answer
178
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 ...
1
vote
0
answers
18
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: ...
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 ...
0
votes
0
answers
268
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';
...
0
votes
1
answer
456
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, ...
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 =...
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....
3
votes
0
answers
223
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 ...
0
votes
1
answer
243
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 ...
2
votes
0
answers
279
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 ...
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 ...
1
vote
2
answers
614
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/.*
...
29
votes
10
answers
41k
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 ...
0
votes
1
answer
68
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 ...
0
votes
0
answers
71
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 ...
3
votes
1
answer
72
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, ...
0
votes
1
answer
80
views
Why does Flow in VS Code give two type definitions for my React function?
I'm using Flow and React to create an Azure Static App in VS Code. The app works, but I'm confused by the type definitions of my functions. I've created a small example in a file annotated with //@...
1
vote
1
answer
177
views
How does React Natives Stylesheet.create work?
Here is the code for the create method.
create<+S: ____Styles_Internal>(obj: S): $ReadOnly<S> {
// TODO: This should return S as the return type. But first,
// we need to codemod ...
2
votes
1
answer
549
views
How to make Flow and Typescript work together in React?
So, how to make Flow and Typescript work together in React? You will ask why you have both in the same project, but I am in the middle of the transition from Flow to Typescript, and for a brief period ...
0
votes
1
answer
573
views
Babel-node can't process flowtype files imported in Typescript file?
I got, it seems, an odd situation where I can't find an answer on the Interwebs. In those case, I think I'm doing something incorrectly or not in a standard way.
Context
an open-source React-Native ...