You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've written a pipe that gets all values from an object, parse strings to numbers or return null for anything else, reject null values, reject negative numbers, and sums the result. Functionally, it works fine, but the typescript inference isn't playing nicely and I'm not sure if it's a bug or some fault of mine.
const mockData = {
foo: '1',
bar: null,
baz: 2,
crud: -1
}
const parseFloatOrNull = v => {
if (typeof v === 'number') {
return v
} else if (typeof v === 'string') {
return Number.parseFloat(v) || null
}
return null
}
console.log(R.pipe(R.values, R.map(parseFloatOrNull), R.reject(R.either(R.isNil, R.lt(R.__, 0))), R.sum)(mockData))
TS shows an error for the R.reject function:
Argument of type '<P extends number, C extends readonly P[] | Record<string, P>>(collection: C) => C' is not assignable to parameter of type '(a: (number | null)[]) => readonly number[]'.
Types of parameters 'collection' and 'a' are incompatible.
Type '(number | null)[]' is not assignable to type 'readonly number[] | Record<string, number>'.
Type '(number | null)[]' is not assignable to type 'Record<string, number>'.
Index signature for type 'string' is missing in type '(number | null)[]'.ts(2345)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've written a pipe that gets all values from an object, parse strings to numbers or return null for anything else, reject null values, reject negative numbers, and sums the result. Functionally, it works fine, but the typescript inference isn't playing nicely and I'm not sure if it's a bug or some fault of mine.
TS shows an error for the R.reject function:
TS Playground
Beta Was this translation helpful? Give feedback.
All reactions