fp-ts
fp-ts copied to clipboard
Bind and BindW improperly passes params through
🐛 Bug report
The following code improperly raises a type error:
const func1 = (i: {arg1: string}) => TE.right('result1')
const func2 = (i: {arg2: string, result1: string}) => TE.right('result2')
pipe(
TE.right({arg1: 'arg1', arg2: 'arg2'}),
TE.bindW('result1', func1),
TE.bindW('result2', func2),
)
This is because this line improperly rewrites the parameter list that gets passed into the next function in the pipe TE.bindW('result1', func1),
Current Behavior
Improper type error
Expected behavior
The params should be passed through using the return type of the previous pipe call rather than the param list of the function passed in.
Reproducible example
Example above
Suggested solution(s)
I'll open an MR to fix this following this bug issue.
Additional context
Your environment
fp-ts 2.11.2
| Software | Version(s) |
|---|---|
| fp-ts | 2.11.2 |
| TypeScript | 4.2.3 |
+1
I keep hitting the same problem. This has been open for quite some time, with a PR to fix it.. What is preventing the fix to be released?
Thx
Reopening because the fix causes a regression (https://github.com/gcanti/fp-ts/pull/1584#issuecomment-1252053927)
@gcanti The ts-pattern problem is confirmed as a limitation in TypeScript (https://github.com/gvergnaud/ts-pattern/issues/111#issuecomment-1261961683). I have a workaround for when the change is made, and it's definitely one to do. (Just not sure whether it should be left for v3.)
The release notes for v2.13.1 suggest that this was fixed in that release but I am still seeing this behaviour after updating and the comments here suggest the fix was removed from the release?
Could you confirm that it is the release notes that are incorrect and I am not going mad lol?
@georgegebbett sorry, I forgot to amend the changelog after reverting the change (the fix was actualy removed from the release)
That makes what I am seeing make sense! Thanks for clarifying!
With TypeScript 5.4, f: (a: NoInfer<A>) => TaskEither<E2, B> might solve the problem.
For example
export const bindW: <N extends string, A, E2, B>(
name: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => TaskEither<E2, B>
) => <E1>(fa: TaskEither<E1, A>) => TaskEither<E1 | E2, { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }> =
bind as any
However, I have no idea how difficult it is to bump TypeScript and find possible regressions because currently, type errors in tests are not being detected.