8000 v4: Type signature of enum input is not properly inferred · Issue #4278 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
v4: Type signature of enum input is not properly inferred #4278
Closed
@pattobrien

Description

@pattobrien

Description

Given the below code:

const myEnum = z.enum(["left", "right", "center", "justify"]);
const myObject = z.object({ myEnum: myEnum });

type MyObject = z.infer<typeof myObject>;
type MyObjectInput = z.input<typeof myObject>;

I would expect MyObjectInput to be of type:

type MyObjectInput = {
    myEnum: "left" | "right" | "center" | "justify";
}

Actual Result

The inferred type signature of MyObjectInput is shown as:

type MyObjectInput = {
    myEnum: z.core.$InferEnumInput<{
        left: "left";
        right: "right";
        center: "center";
        justify: "justify";
    }>;
}

NOTE: This is only an issue with MyObjectInput, not MyObject (i.e. output type).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0