Skip to content

Should InferInput return a type that is deep readonly? #1346

@jhnns

Description

@jhnns

I've encountered a problem and wanted to get your opinion on it. I have the following simplified example:

const Schema = v.pipe(v.tuple([]), v.readonly());

const createTuple = () => [] as const;

type Input = v.InferInput<typeof Schema>;

const input: Input = createTuple();
//           ^ The type 'readonly []' is 'readonly' and cannot be assigned to the mutable type '[]'

I've set up a Stackblitz here so you can play around with it: https://stackblitz.com/edit/stackblitz-starters-qhcxx34a?file=index.ts (you may need to log in to see the type error)

One possible solution would be for InferInput to always return a type wrapped in ReadonlyDeep. In my opinion, this is correct, as parse does not mutate the input as far as I understand.

Is this correct, or are there side effects that I haven't considered yet?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions