question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relation model definitions throw TypeScript errors

See original GitHub issue

Generated 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:open
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
jamespb97commented, Mar 16, 2022

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:

{
  "includes": ["prisma/zod"]
}
1reaction
siddharthsharma94commented, Dec 22, 2021

Hey @CarterGrimmeisen! I’m still seeing this issue, with the TS errors in version ^0.3.2

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found