unzip typings seem to behave inconsistently depending on whether point-free or with-argument style is used.
import { pipe } from 'fp-ts/es6/pipeable'
import * as L from 'fp-ts/es/6/Array';
const f = (xs: Array<number>): [Array<number>, Array<number>] =>
pipe(
xs,
L.map(n => [n + 1, n] as [number, number]),
L.unzip,
);
produces:
Type '[unknown[], unknown[]]' is not assignable to type '[number[], number[]]'.
Type 'unknown[]' is not assignable to type 'number[]'.
Type 'unknown' is not assignable to type 'number'.ts(2322)
However, if you replace the last line with pairs => L.unzip(pairs) it works perfectly fine in terms of types.
I suspect it's due to multiple overloads of unzip (introduced in 2.5). I guess if no other workaround is possible we should make unzip woking on NonEmptyArray a separate function in appropriate module?
| Software | Version(s) |
| ---------- | ---------- |
| fp-ts | 2.5.0 |
| TypeScript | 3.7.3 |
@vicrac mmhh I can't repro, the reproducible example doesn't raise any error in my local project
Hmm, that's weird. I use Typescript 3.7.3, maybe that's the problem. I'll try to open a PR with reproduction in tests.
Happens for me also,
[email protected]
[email protected]
@vicrac never mind forgot to update fp-ts, sorry
@gcanti no problem :smile: Note: that's definitely unzip overload problem, since removing second overload fixes it.
// const result: [unknown[], unknown[]] // <= regression, was [number[], number[]]
export const result = pipe([[1, 2]], A.unzip)
@vicrac This is a regression, I'll revert https://github.com/gcanti/fp-ts/pull/1120 and add specialized zip, zipWith and unzip to NonEmptyArray
@gcanti Sorry to bother you, but could you explain why did this failed, given these overloads seem to be reasonable? I've spent half an hour trying to figure it out and ended up with literally no idea...
@vicrac honestly? no idea. Keep in mind that there are many places in the fp-ts codebase where type inference doesn't "just work" and I need either an eta expansion (like the pairs => L.unzip(pairs) above) or an explicit type annotation.
I thought that overloadings were "safe"... lesson learned (the hard way).
@vicrac @GrzegorzKazana patch released, could you please try it out?
Just checked, works as intended, both for Array.unzip and NonEmptyArray.unzip. Thanks a lot for quick response 馃
Checked too, works just fine :ok_hand: Thanks!
Most helpful comment
@vicrac This is a regression, I'll revert https://github.com/gcanti/fp-ts/pull/1120 and add specialized
zip,zipWithandunziptoNonEmptyArray