Possibly better RxJS pipe typings? #6671
Replies: 2 comments 1 reply
-
Moved to discussion as there's already filed issue regarding number of overload, and this is a suggestion. |
Beta Was this translation helpful? Give feedback.
-
There's a few challenges with this implementation though. Although the typings for this pipe verify that everything is consistent and returns the correct input/output, it doesn't let typescript infer any of the parameters. Take this example (it's essentially the one you have in gist, but I've removed the type anotation of the parameter for the second operator): pipe(
(_: string) => 0, // Error: Argument of type '(_: string) => number' is not assignable to 'never'
(value) => String(value), // Error: Parameter 'value' implicitly has an 'any' type
(_: string) => true,
); I would expect in this case for TS to infer that This is specially relevant with rxjs, where you mostly expect everything to be inferred: pipe(
(value: number) => of(value),
map(myValue => myValue.toFixed(3)), // myValue is inferred as number
filter(myString => myString.includes('2')) // myString is inferred as string
); I've tried many times to write the types of a pipe function that can do this, but I've never managed to get something working. It would be amazing to see a solution to this problem! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I know it's unlikely for someone to use 9+ operators in a pipe... but this is really bugging me...
pipe.ts' typings
seems pretty huge, redundant, and unnecessary, and I want to help reduce it so:I made a simple prototype with this working in this gist (updated)
Currently, it takes in any amount of unary functions, and does the following:
Thoughts, anyone?
Let me know if this can be possibly added.
Related issues: #4177
Beta Was this translation helpful? Give feedback.
All reactions