As I understand, fp-ts 3 will be readonly only. Should experimental io-ts decode to readonly types as well?
@steida IMO yes, they definitely should.
A first consideration: the following pattern (which can be used to clean a Decoder signature)
import * as D from 'io-ts/Decoder'
const _Person = D.type({
name: D.string,
age: D.number
})
interface Person extends D.TypeOf<typeof _Person> {}
const Person: D.Decoder<unknown, Person> = _Person
can be slightly modified to support readonly types
import * as D from 'io-ts/Decoder'
const _Person = D.type({
name: D.string,
age: D.number
})
interface Person extends Readonly<D.TypeOf<typeof _Person>> {}
const Person: D.Decoder<unknown, Person> = _Person
so we may not have to do anything.
The built-in Readonly type can also be used to define a readonly combinator
import { identity } from 'fp-ts/function'
export const readonly: <I, A>(decoder: D.Decoder<I, A>) => D.Decoder<I, Readonly<A>> = identity
const Person = readonly(
D.type({
name: D.string,
age: D.number
})
)
can be slightly modified to support readonly types
so we may not have to do anything.
It looks weird to define all models like that.
Most helpful comment
@steida IMO yes, they definitely should.