2,387
questions
0
votes
0
answers
19
views
Flowtype: Partial enums
Regarding Flow enums, is it possible to have partial subsets?
For example, let's say you have the following:
enum Size {
Mini = 'mini',
Tiny = 'tiny',
Small = 'small',
Medium = 'medium'...
0
votes
0
answers
21
views
vue/compiler-sfc Doesn't recognise Flow.js syntax
I am trying to migrate a Vue 2 application to Vue 3.
The application uses Flow.js and Webpack / Vue CLI for the build.
I am trying to follow the approach with the compatibility build.
So I:
Installed ...
0
votes
0
answers
11
views
string is incompatible with $SymbolToStringTag
I can't use Map with string key in Flow?
Example
let m : Map<string, number> = new Map(); // or {}
m["hello"] = 10;
0
votes
0
answers
29
views
Kotlin/JS exhaustivity check on enums?
I am investigating into the integration of a Kotlin Multiplatform library into an existing JS project. I am struggling with the exhaustivity check on enums and sealed classes on the JS side.
In JS, an ...
0
votes
1
answer
44
views
Cannot assign object literal when creating a union object in JavaScript
I'm trying to write a function that creates an object with all the common attributes of a union type but as far as I can tell it is not possible without a FlowFixMe. Here's an example
type AType = &...
0
votes
0
answers
16
views
Tell Flowtype to read files before analysis
Working in a vanilla JS project (NOT the vanilla framework), it would be nice to be able to preload some JS files before analyzing the "main" file you want to check. Is this possible? Or do ...
1
vote
1
answer
28
views
Possible to annotate inline "this" with comment types with Flow?
Getting this error:
Missing an annotation on implicit this parameter of function.
Would be nice to be able to annotate this with comment types. Possible?
https://flow.org/en/docs/types/comments/
0
votes
1
answer
15
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>: ...
0
votes
1
answer
45
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<...
0
votes
1
answer
19
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?
1
vote
0
answers
25
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....
1
vote
0
answers
46
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
176
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
40
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
479
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
121
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
36
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
365
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
72
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
40
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
54
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
37
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
30
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: ...
1
vote
0
answers
212
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
98
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.
...
74
votes
4
answers
54k
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
42
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
97
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
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: &...
2
votes
2
answers
525
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
322
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
71
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
41
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
231
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
381
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
109
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
87
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
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, ...
1
vote
0
answers
177
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
188
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
210
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
20
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
312
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
860
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
2k
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
82
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
276
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
324
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 ...