Relation model definitions throw TypeScript errors
See original GitHub issueGenerated Zod schemas for complete records (with relations) report errors, see test/functional/recursive/expected/comment.ts
:
Type 'ZodLazy<ZodObject<extendShape<{ id: ZodString; author: ZodString; contents: ZodString; parentId: ZodString; }, { parent: ZodType<CompleteComment, ZodTypeDef, CompleteComment>; children: ZodArray<...>; }>, "strip", ZodTypeAny, { ...; }, { ...; }>>' is not assignable to type 'ZodType<CompleteComment, ZodTypeDef, CompleteComment>'.
Types of property '_type' are incompatible.
Type '{ id?: string; contents?: string; author?: string; parentId?: string; parent?: CompleteComment; children?: CompleteComment[]; }' is not assignable to type 'CompleteComment'.
Property 'parent' is optional in type '{ id?: string; contents?: string; author?: string; parentId?: string; parent?: CompleteComment; children?: CompleteComment[]; }' but required in type 'CompleteComment'.ts(2322)
I’ll have a closer look and open a PR if I find a fix.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Documentation - Understanding Errors - TypeScript
Whenever TypeScript finds an error, it tries to explain what went wrong in as much detail as possible. Because its type system is...
Read more >TypeScript errors and how to fix them
A list of common TypeScript errors and how to fix them.
Read more >Chapter 1. Getting to Know TypeScript
TypeScript adds a type system that models JavaScript's runtime behavior and tries to spot code which will throw exceptions at runtime. But you...
Read more >TypeScript Express tutorial #3. Error handling and validating ...
Express Error handling middleware. First, let's create a class that we are going to use to throw errors. src/exceptions/HttpException.ts ...
Read more >How can I safely access caught Error properties in TypeScript?
11 · @etheryte while it is possible to throw any type of value, why does typescript does not allow the author to explicitly...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed it, make sure your generated zod folder is in your includes in tsconfig! https://github.com/colinhacks/zod/issues/533
By default this generator puts zod in prisma folder which wasn’t included in my tsconfig. Either move the zod folder to be somewhere else or include in tsconfig like so:
Hey @CarterGrimmeisen! I’m still seeing this issue, with the TS errors in version
^0.3.2