Flow upgrade to 0.64 results in bunch of new errors - react-native

I recently upgraded flow-bin and .flowconfig from 0.53 to 0.64 and now flow is resulting in bunch of new errors inside react-native framework files.
What can I do about this situation?
Error: node_modules/react-native/Libraries/Components/ScrollResponder.js:480
480: var { animated, ...rect } = rect;
^^^^^^^ rect. This type is incompatible with
472: rect: { x: number, y: number, width: number, height: number, animated?: boolean },
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ object type
Property `animated` is incompatible:
472: rect: { x: number, y: number, width: number, height: number, animated?: boolean },
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ property `animated`. Property not found in
480: var { animated, ...rect } = rect;
^^^^^^^ rect
Error: node_modules/react-native/Libraries/Inspector/Inspector.js:104
104: clearTimeout(_hideWait);
^^^^^^^^^ null. This type is incompatible with the expected param type of
733: declare function clearTimeout(timeoutId?: TimeoutID): void;
^^^^^^^^^ TimeoutID. See lib: /tmp/flow/flowlib_213409a3/core.js:733
Error: node_modules/react-native/Libraries/Interaction/InteractionManager.js:171
171: _nextUpdateHandle = setTimeout(_processUpdate, 0 + DEBUG_DELAY);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TimeoutID. This type is incompatible with
182: _nextUpdateHandle = 0;
^ number
Error: node_modules/react-native/Libraries/Lists/FlatList.js:465
v--------------------------------
465: this._virtualizedListPairs.push({
466: viewabilityConfig: this.props.viewabilityConfig,
467: onViewableItemsChanged: this._createOnViewableItemsChanged(
...:
470: });
-^ rest parameter array of call of method `push`. Has some incompatible type argument with
249: push(...items: Array<T>): number;
^^^^^^^^ array type. See lib: /tmp/flow/flowlib_213409a3/core.js:249
Type argument `T` is incompatible:
v
465: this._virtualizedListPairs.push({
466: viewabilityConfig: this.props.viewabilityConfig,
467: onViewableItemsChanged: this._createOnViewableItemsChanged(
...:
470: });
^ object literal. This type is incompatible with
476: _virtualizedListPairs: Array<ViewabilityConfigCallbackPair> = [];
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ViewabilityConfigCallbackPair
Property `viewabilityConfig` is incompatible:
466: viewabilityConfig: this.props.viewabilityConfig,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. Inexact type is incompatible with exact type
26: viewabilityConfig: ViewabilityConfig,
^^^^^^^^^^^^^^^^^ ViewabilityConfig. See: node_modules/react-native/Libraries/Lists/ViewabilityHelper.js:26
Error: node_modules/react-native/Libraries/Lists/FlatList.js:558
558: return keyExtractor(items, index);
^^^^^ array type. This type is incompatible with the expected param type of
151: keyExtractor: (item: ItemT, index: number) => string,
^^^^^ ItemT
Error: node_modules/react-native/Libraries/Lists/ViewabilityHelper.js:91
91: this._timers.forEach(clearTimeout);
^^^^^^^^^^^^ function type. This type is incompatible with the expected param type of
572: forEach(callbackfn: (value: T, index: T, set: Set<T>) => mixed, thisArg?: any): void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. See lib: /tmp/flow/flowlib_213409a3/core.js:572
The first parameter is incompatible:
77: _timers: Set<number> = new Set();
^^^^^^ number. This type is incompatible with
733: declare function clearTimeout(timeoutId?: TimeoutID): void;
^^^^^^^^^ TimeoutID. See lib: /tmp/flow/flowlib_213409a3/core.js:733
Error: node_modules/react-native/Libraries/Lists/ViewabilityHelper.js:200
200: this._timers.delete(handle);
^^^^^^ TimeoutID. This type is incompatible with the expected param type of
77: _timers: Set<number> = new Set();
^^^^^^ number
Error: node_modules/react-native/Libraries/Lists/ViewabilityHelper.js:207
207: this._timers.add(handle);
^^^^^^ TimeoutID. This type is incompatible with the expected param type of
77: _timers: Set<number> = new Set();
^^^^^^ number
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:484
v
484: this.scrollToIndex({
485: animated: false,
486: index: this.props.initialScrollIndex,
487: }),
^ object literal. This type is incompatible with the expected param type of
v
266: scrollToIndex(params: {
267: animated?: ?boolean,
268: index: number,
...:
271: }) {
^ object type
Property `index` is incompatible:
486: index: this.props.initialScrollIndex,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null or undefined. This type is incompatible with
268: index: number,
^^^^^^ number
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:484
v
484: this.scrollToIndex({
485: animated: false,
486: index: this.props.initialScrollIndex,
487: }),
^ object literal. This type is incompatible with the expected param type of
v
266: scrollToIndex(params: {
267: animated?: ?boolean,
268: index: number,
...:
271: }) {
^ object type
Property `index` is incompatible:
486: index: this.props.initialScrollIndex,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. This type is incompatible with
268: index: number,
^^^^^^ number
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:500
500: clearTimeout(this._initialScrollIndexTimeout);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ number. This type is incompatible with the expected param type of
733: declare function clearTimeout(timeoutId?: TimeoutID): void;
^^^^^^^^^ TimeoutID. See lib: /tmp/flow/flowlib_213409a3/core.js:733
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1016
1016: distanceFromEnd < onEndReachedThreshold * visibleLength &&
^^^^^^^^^^^^^^^^^^^^^ null or undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1016
1016: distanceFromEnd < onEndReachedThreshold * visibleLength &&
^^^^^^^^^^^^^^^^^^^^^ undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1094
1094: this.props.onEndReachedThreshold * visibleLength / 2;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ null or undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1094
1094: this.props.onEndReachedThreshold * visibleLength / 2;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1170
1170: distanceFromEnd < onEndReachedThreshold * visibleLength
^^^^^^^^^^^^^^^^^^^^^ null or undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1170
1170: distanceFromEnd < onEndReachedThreshold * visibleLength
^^^^^^^^^^^^^^^^^^^^^ undefined. The operand of an arithmetic operation must be a number.
Error: node_modules/react-native/Libraries/Lists/VirtualizedList.js:1247
1247: return frame;
^^^^^ object type. This type is incompatible with the expected return type of
v
1210: ): ?{
1211: length: number,
1212: offset: number,
...:
1215: } => {
^ object type
Property `inLayout` is incompatible:
v
1210: ): ?{
1211: length: number,
1212: offset: number,
...:
1215: } => {
^ property `inLayout`. Property not found in
1247: return frame;
^^^^^ object type
Error: node_modules/react-native/Libraries/Lists/VirtualizedSectionList.js:236
236: key: keyExtractor(viewable.item, info.index),
^^^^^^^^^^ null or undefined. This type is incompatible with the expected param type of
101: keyExtractor: (item: Item, index: number) => string,
^^^^^^ number
Error: node_modules/react-native/Libraries/StyleSheet/flattenStyle.js:36
36: return getStyle(style);
^^^^^^^^^^^^^^^ number. This type is incompatible with the expected return type of
29: function flattenStyle(style: ?StyleObj): ?Object {
^^^^^^ object type
Found 30 errors
error Command failed with exit code 2.

Related

Bootstrap 5 - SassError: argument `$color` of `red($color)` must be a color

yesterday I updated my Vue project to the latest Bootstrap version (5.2) and now I have a SASS Error while starting.
ERROR Failed to compile with 1 error 10:45:42
error in ./src/assets/scss/config/modern/app.scss
Syntax Error: SassError: argument `$color` of `red($color)` must be a color
on line 185 of node_modules/bootstrap/scss/_functions.scss, in function `red`
from line 185 of node_modules/bootstrap/scss/_functions.scss, in function `luminance`
from line 174 of node_modules/bootstrap/scss/_functions.scss, in function `contrast-ratio`
from line 159 of node_modules/bootstrap/scss/_functions.scss, in function `color-contrast`
from line 7 of node_modules/bootstrap/scss/_accordion.scss
from line 29 of node_modules/bootstrap/scss/bootstrap.scss
from line 15 of src/assets/scss/config/modern/bootstrap.scss
from line 19 of src/assets/scss/config/modern/app.scss
>> "r": red($color),
It's about this code snippet:
// File: _functions.scss
// Return WCAG2.1 relative luminance
// See https://www.w3.org/TR/WCAG/#dfn-relative-luminance
// See https://www.w3.org/TR/WCAG/#dfn-contrast-ratio
#function luminance($color) {
$rgb: (
"r": red($color),
"g": green($color),
"b": blue($color)
);
#each $name, $value in $rgb {
$value: if(divide($value, 255) < .03928, divide(divide($value, 255), 12.92), nth($_luminance-list, $value + 1));
$rgb: map-merge($rgb, ($name: $value));
}
#return (map-get($rgb, "r") * .2126) + (map-get($rgb, "g") * .7152) + (map-get($rgb, "b") * .0722);
}
And that's the trigger:
// File: _accordion.scss
// scss-docs-start accordion-css-vars
--#{$prefix}accordion-color: #{color-contrast($accordion-bg)};
I know, the error says, the function gets a wrong parameter, which is not of type color, but I never user it my self.
How can I fix this error and why does it occur?

dataframe-go: How to filter using < > operators?

I'm trying to do a simple filter in dataframe-go. I adapted from the Github example and tried to use a simple > operator in the Filter Function, but the compiler gave invalid operation: vals["day"] > 4 (operator > not defined on interface) error (see my code below)
Ok, so I changed the type to map[string]int64 but then, it gave the error: cannot convert func literal (type func(map[string]int64, int, int) (dataframe.FilterAction, error)) to type dataframe.FilterDataFrameFn.
I'm very familiar with R DataFrame/Table and Pandas but dataframe-go's API is rather convoluted. The only web resource I found is this but the author also stated he couldn't understand the filter API.
Any help is appreciated, thanks!
s1 := dataframe.NewSeriesInt64("day", nil, 1, 2, 3, 4, 5, 6, 7, 8)
s2 := dataframe.NewSeriesFloat64("sales", nil, 50.3, 23.4, 56.2, nil, nil, 84.2, 72, 89)
df := dataframe.NewDataFrame(s1, s2)
// Try filtering
filterFn := dataframe.FilterDataFrameFn(
func(vals map[string]int64, row, nRows int) (dataframe.FilterAction, error) {
//func(vals map[interface{}]interface{}, row, nRows int) (dataframe.FilterAction, error) {
if vals["day"] > 4 { // <= This is where I changed things
return dataframe.KEEP, nil
}
return dataframe.DROP, nil
})
ctx := context.Background()
dt_filtered, _ := dataframe.Filter(ctx, df, filterFn)
fmt.Print(dt_filtered)
You have to pass a function with the required signature, so vals must be a map[interface{}]interface{}. This is required because Go is not an interpreted language, and the code calling that function you passed as an argument has no compile-time knowledge of the function passed in.
Since your values are interface{}s, you have to convert them to the correct type to operate with them:
if ivalue, ok:=vals["day"].(int64); ok { // Check if the value is int64, and go ahead if so
if ivalue > 4 {
return dataframe.KEEP, nil
}
}

swagger-codegen ABAP object nested

I'm currently writing a generator for the ABAP language and I'm facing one problem.
In the service that I have to transform I have the following object:
"router_options": {
"track": true,
"motorway": true,
"toll": true,
"trailers": 0,
"weight": 0,
"weight_per_axle": 0,
"height": 0,
"width": 0,
"length": 0,
"hazardous_goods": "explosive",
"max_walk_distance": 0,
"approach": "unrestricted",
"snap": 0,
"strict_restriction": true
}
when I execute the codegen generator the code generated give me the following code
i_router_options_track type bool optional
i_router_options_motorway type bool optional
i_router_options_toll type bool optional
i_router_options_trailers type int optional
i_router_options_weight type float optional
i_router_options_weight_per_axle type float optional
i_router_options_height type float optional
i_router_options_width type float optional
i_router_options_length type float optional
i_router_options_hazardous_goods type string optional
i_router_options_max_walk_distance type float optional
The approach would be more something like declaring a type of structure in the operation part like that
types : begin of ts_router_options,
track type bool,
motorway type bool,
toll type bool,
trailers type int,
weight type float,
weight_per_axle type float,
height type float,
width type float,
length type float,
hazardous_goods type string,
max_walk_distance type float,
approach type string,
snap type float,
strict_restriction type bool,
end of ts_router_options.
and use it like below :
data : router_options type ts_router_options.
router_options-height = '10,10'
Does anyone can help me for that ?

How to use ByteArray.getOrElse

I don't undertand how to specify the default value for `ByteArray.getOrElse() function.
I tried:
myInt = dat.getOrElse(0, 0).toInt()
but compiler complains with the following error:
The integer literal does not conform to the expected type (Int) -> Byte
How to specify the default value?
The expected type of the second argument (defaultValue) is (Int) -> Byte which is a lambda that takes an Int and returns a Byte.
myInt = dat.getOrElse(index = 100, defaultValue = {
i ->
// use i to calcuate your Byte that should be returned...
// or return a fixed value
i * 1 // for example
})
Signature of getOrElse:
fun ByteArray.getOrElse(
index: Int,
defaultValue: (Int) -> Byte
): Byte
The second argument is a function literal
myInt = dat.getOrElse(100, { /** what is there is no element 100*/ 0 })

How do I type lodash/fp curried functions?

I'm trying to add to the flow-typed typings. I'm starting with the lodash/fp module because that is most useful to myself. However, I'm struggling with how to type it correctly.
A simple example if dropRightWhile:
declare function dropRightWhile<T>(iteratee: (val: T)=>boolean, data?: Array<T>): Array<T> | (data: Array<T>)=>Array<T>;
This is my attempt to type it. dropRightWhile must take an iteratee, and it could take the data. If you don't give it data then it returns a function that takes the data, but if you give it data then it returns an array.
The type I have made doesn't strictly make the connection between number of arguments and return type. However, when I try to use a curried dropRightWhile I get an error
var c = dropRightWhile((x) => x> 0); c([0, 1, 2, 3]);
error: Function cannot be called on array type
I would've thought that since dropRightWhile can return a function then I would be able to call it, but it seems the array type is getting in the way.
Any suggestions?
You can define 2 overloadings
declare function dropRightWhile<T>(iteratee: (val : T) => boolean, data : Array<T>) : Array<T>;
declare function dropRightWhile<T>(iteratee: (val : T) => boolean): (data : Array<T>) => Array<T>;
// tests
const iteratee = x => x > 0;
(dropRightWhile(iteratee)([0, 1, 2, 3]) : Array<number>);
(dropRightWhile(iteratee, [0, 1, 2, 3]) : Array<number>)