gcanti / fp-ts

Functional programming in TypeScript
https://gcanti.github.io/fp-ts/
MIT License
10.9k stars 503 forks source link

Predicate cannot be piped to dropLeftWhile in 2.11 #1542

Open samhh opened 3 years ago

samhh commented 3 years ago

🐛 Bug report

fp-ts: 2.11.0 TypeScript: 4.3.5

Current Behavior

A predicate with a type argument other than unknown cannot be piped to Array's dropLeftWhile in 2.11.


declare const f: Predicate<string>

// works
A.dropLeftWhile(f)

// doesn't work
pipe(f, A.dropLeftWhile)
Argument of type 'Predicate<string>' is not assignable to parameter of type 'Predicate<unknown>'.
  Types of parameters 'a' and 'a' are incompatible.
    Type 'unknown' is not assignable to type 'string'.

Expected behavior

It should probably typecheck. The above is a minimal repro, but the actual issue I've encountered is that fp-ts-std/String::dropLeftWhile no longer typechecks following an upgrade to fp-ts 2.11, where it worked in 2.10. This is the only issue I've encountered in that project but if this is deemed a regression it's possible it affects other functions as well.

samhh commented 3 years ago

I think this behaviour may have been present in takeLeftWhile for longer.