Handling Readonly Properties After Schema Decoding in Effect Typescript

After doing a Schema.decodeUnknown, all the properties are readonly.
But doesn't that make it super inconvenient to use the parsed values?

Example:
const mySchema = Schema.Array(Schema.Number)
const len = (arr: []) => arr.length

const res = pipe(
  [1, 2, 3],
  Schema.decodeUnknown(mySchema),
  Effect.map(len)
)

This will not compile, because len takes a mutable array as input, but is getting a readonly.

How do we deal with that? Surely there is a more elegant solution than having to add "readonly" to all our function types, isn't there?

https://effect.website/play/#74820cdde077
Was this page helpful?