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

type error #2011

Closed
Ezreal09 opened this issue Feb 8, 2023 · 4 comments
Closed

type error #2011

Ezreal09 opened this issue Feb 8, 2023 · 4 comments

Comments

@Ezreal09
Copy link

Ezreal09 commented Feb 8, 2023

in type.d.ts file, Some type errors occur here: Writeable<FilterEnum<T, ToExclude[number]>>
version: '3.20.3'
image

@SimplyLinn
Copy link

Having done some investigation.

Issue is present in typescript 4.9.5

Removing "Writeable<>" wrapping the FilterEnum solves it for me, as the returned type from FilterEnum is already writeable.

@SimplyLinn
Copy link

I think this PR introduced an issue once it's compiled to a d.ts file.

The exclude method becomes this type declaration:

declare class ZodEnum<T extends [string, ...string[]]> extends ZodType<T[number], ZodEnumDef<T>> {
    exclude<ToExclude extends readonly [T[number], ...T[number][]]>(values: ToExclude): ZodEnum<Writeable<FilterEnum<T, ToExclude[number]>>>;
}

Wrapping the output of FilterEnum in Writeable makes the typechecker not see it as matching the constraint set by ZodEnum.

The wrapping of Writeable, I think, is due to the order of the createZodEnum functions overloads?

I will investigate whether my assumption is correct, and potentially open a PR

@paulsmithkc
Copy link

paulsmithkc commented Feb 8, 2023

Seeing the same error with:

zod@3.20.3
typescript@4.9.5

node_modules/zod/lib/types.d.ts(668,97):***error***TS2344:***Type***'Writeable<FilterEnum<T,***ToExclude[number]>>'***does***not***satisfy***the***constraint***'[string,***...string[]]'.

This error does not appear with the previous version of zod (3.20.2)

This same error appears for typescript versions 4.8 and greater.

@colinhacks
Copy link
Owner

Fixed in Zod 3.20.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants