Effect CommunityEC
Effect Community•3y ago•
7 replies
bste

Error when creating instance of Case data type using Schema

Hey all. I'm trying to use Schema to validate some json back from Dynamo and then create an instance of a Case data type but I'm getting a readonly assignment error.
The Case is defined as (I get the same error if I define a tagged class too)
export interface Pet extends Data.Case {
  _tag: "Pet",
  readonly id: PetId,
  readonly name: [string, ...string[]],
  readonly weight: number,
  readonly dateOfBirth: string
}

export const Pet = Data.tagged<Pet>("Pet")


and the schema I'm using to validate from Dynamo is
class PetEntitySchema extends S.Class<PetEntitySchema>()({
  id: S.UUID,
  name: S.nonEmptyArray(S.string),
  weight: S.number,
  species: S.string,
  dateOfBirth: S.string
}) { }


I notice that the S.nonEmptyArray results in a readonly field, where as the others don't, which is causing me the error, as when I try to do
pipe(S.parse(PetEntitySchema)(a.data), Effect.map(p => Pet({ id: PetId(p.id), name: p.name, weight: p.weight, dateOfBirth: p.dateOfBirth })))

the
name
field gives me The type 'readonly [string, ...string[]]' is 'readonly' and cannot be assigned to the mutable type '[string, string[]]'

anyone know what I'm doing wrong?
Was this page helpful?