Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ZodFormattedError type breaks for ReadonlyArrays. #3565

Open
Ben-at-Catalyst opened this issue Jun 12, 2024 · 0 comments
Open

[Bug]: ZodFormattedError type breaks for ReadonlyArrays. #3565

Ben-at-Catalyst opened this issue Jun 12, 2024 · 0 comments

Comments

@Ben-at-Catalyst
Copy link

The following TypeScript code gives a compiler error:

    type Foo = {
      ids: ReadonlyArray<string>;
    };

    const error: ZodFormattedError<Foo> = {
      _errors: [],
      ids: { _errors: [] },
    };

The error:

[Filename]: error TS2322: Type '{ _errors: never[]; }' is not assignable to type 'ZodFormattedError<readonly string[], string>'.
  Type '{ _errors: never[]; }' is missing the following properties from type 'readonly ({ _errors: string[]; } | undefined)[]': length, concat, join, slice, and 26 more.

85       ids: { _errors: [] },
         ~~~

[Filename]:
    80       ids: ReadonlyArray<string>;
             ~~~
    The expected type comes from property 'ids' which is declared here on type 'ZodFormattedError<Foo>'

The weird thing is if I change my type Foo to use an Array instead of a ReadonlyArray the error goes away. This works:

    type Foo = {
      ids: Array<string>;
    };

    const error: ZodFormattedError<Foo> = {
      _errors: [],
      ids: { _errors: [] },
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant