gcanti / monocle-ts

Functional optics: a (partial) porting of Scala monocle
https://gcanti.github.io/monocle-ts/
MIT License
1.05k stars 52 forks source link

pipe and composition of L.findFirst doesn't compile due to difference in readonly attribute #154

Open felher opened 3 years ago

felher commented 3 years ago

🐛 Bug report

First of all, let me just say that I like the new pipe-modules very much. Let' me also say that I'm not sure this is actually a bug. Maybe I'm just doing something wrong. But I felt compelled to choose one of the templates. Last but not least, thank you very much for monocle-ts. It's a great library!

Current Behavior


import * as L from 'monocle-ts/lib/Lens';

interface Persons {
  entries: string[];
}

const findWaldo = pipe(
  L.id<Persons>(),
  L.prop("entries"),
  L.findFirst(p => p === "Waldo")
)

This does not compile. The error I get is:

Argument of type '<S>(sa: Lens<S, readonly string[]>) => Optional<S, string>' is not assignable to parameter of type '(b: Lens<Persons, string[]>) => Optional<Persons, string>'.
  Types of parameters 'sa' and 'b' are incompatible.
    Type 'Lens<Persons, string[]>' is not assignable to type 'Lens<Persons, readonly string[]>'.
      Types of property 'set' are incompatible.
        Type '(a: string[]) => (s: Persons) => Persons' is not assignable to type '(a: readonly string[]) => (s: Persons) => Persons'.
          Types of parameters 'a' and 'a' are incompatible.
            The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.  TS2345

    362 |   L.id<Persons>(),
    363 |   L.prop("entries"),
  > 364 |   L.findFirst(p => p === "Waldo")
        |   ^
    365 | )

Expected behavior

It should compile.

Your environment

cat package.json | grep -E "typescript|-ts
    "monocle-ts": "^2.3.5",
    "fp-ts": "^2.9.5",
    "typescript": "^4.1.3",