Giter Club home page Giter Club logo

Comments (2)

colinhacks avatar colinhacks commented on July 1, 2024 1

Sorry for the inconvenience with this. The short answer is that this has been solved in 3.23.2 by setting the default Output and Input back to any from unknown (as in 3.23.0). This behavior is more intuitive in more cases.

Were that not the case, the real solution here would be to extract both HelloOutput and HelloInput like so (if I'm understanding correctly). That is:

type Branded<T, Brand> = T & { __brand: Brand };
type BrandedString = Branded<string, "BrandedString">;
const aBrandedString = z.string() as unknown as z.ZodSchema<BrandedString>;

const helloSchema = z.object({
  name: aBrandedString,
});
type HelloOutput = z.output<typeof helloSchema>;
type HelloInput = z.input<typeof helloSchema>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const func = (hello: z.ZodObject<any, any, any, HelloOutput, HelloInput>) => {
  // ...
};

const funcResult = func(helloSchema); // this type works now

from zod.

emanuel-lundman avatar emanuel-lundman commented on July 1, 2024

I can see you closed the issue.
Just jotting down for history.

I had tested 3.23, but that didn't do it.
However, the new 3.24 did. (I can see that it reverted back to Input = Output).

The real solution provided in code I don't think would help us because in our real code the func is a generic (I mentioned it briefly but not in the simplified example code). All we know at the time of writing is the generic type, we don't know the schema. So if I'm not forgetting anything obvious (bit tired after a busy week) in our case, the solution wouldn't be the desired route we would like to take, would mean adding a lot of code.

Anyway, thank you for your response!
And since the reversion in 3.24 it's all working again.

from zod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.