Comments (2)
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.
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)
- 3.22.5 exists on npmjs but not on github HOT 1
- Website Redesign ?
- Add runtime introspection of the constructor provided to `z.instanceof`
- Add public API introspection of the element schema for `z.ZodSet` HOT 2
- coerce.date() is not respected by safeParse HOT 1
- is not assignable to parameter of type 'AnyZodObject'. Types have separate declarations of a private property '_cached' HOT 1
- Wrong default branch in github actions files HOT 1
- Unable to pass `z.ZodType` as argument to `merge` HOT 1
- IPv6 validation error HOT 1
- Zod error always blank in latest version of Chrome HOT 6
- ZodFormattedType does not include the fields in TypeScript
- Zod Async Refine always returning false HOT 1
- `#cache` private field in ZodEnum makes it incompatible with Proxy HOT 1
- literal uses `\"` in error message
- Usage of .nonstrict() which is deprecated instead of .passthrough() in some tests
- infer literal in discriminatedUnion fails typecheck but not parse
- Add a .precision(number) option to numbers which checks the number of digits after the decimal point
- zod safeparse not working with nextjs server action useFormState hok HOT 1
- Descriptions from root schema carry over to schemas created with a chained `.array()`
- How make field optional but have minimal character HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zod.