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.

Support zod's infer type

See original GitHub issue

When using a Zod validator and then passing it to TSOA, it throws this error: Error: No matching model found for referenced type infer.

Types File

export const MyValidator = z.object({
  result: z.object({
    price: z.string().nonempty()
  }),
  code: z.number(),
  msg: z.string().nonempty()
})
export type MyResponse = z.infer<typeof MyValidator>

Then use it in TSO

 @Get()
  public async getRequest (): Promise<MyResponse> {
 

Sorting

  • I’m submitting a …

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn’t already been submit

Expected Behavior

When running yarn tsoa spec-and-routes I expect TSOA to be able to use the inferred type generated by Zod.

Current Behavior

It crashes with

Generate routes error.
 Error: No matching model found for referenced type infer.
    at new GenerateMetadataError (/Users/caseygibson/Documents/Github/node_modules/@tsoa/cli/dist/metadataGeneration/exceptions.js:22:28)

Context (Environment)

Version of the library: “^3.14.1” Version of NodeJS: v14.17.4

  • Confirm you were using yarn not npm: [X]

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:20
  • Comments:14

github_iconTop GitHub Comments

4reactions
WoHcommented, Aug 1, 2022

I’ve labeled this to avoid the bot. Please vote instead of commenting, and feel free to open a PR to fix this.

2reactions
WoHcommented, Dec 1, 2022

I assume because ReturnType is a type reference to a type that we already try to resolve via the mechanism I described.

Read more comments on GitHub >

github_iconTop Results From Across the Web

colinhacks/zod: TypeScript-first schema validation ... - GitHub
With Zod, you declare a validator once and Zod will automatically infer the static TypeScript type. It's easy to compose simpler types into...
Read more >
Schema validation in TypeScript with Zod - LogRocket Blog
In this article, you will learn about schema design and validation in Zod and how to run it in a TypeScript codebase at...
Read more >
Infer type from key of object inside an array Zod - Stack Overflow
The way I would suggest doing this is to pull out the wordType field as a separate schema which you would then use...
Read more >
ZOD - TypeScript-first schema data validation - fun4code.com
Zod is TypeScript-first schema validation library with static type inference from schema object. Validate at runtime and compile-time.
Read more >
TypeScript-First Schema Validation with Static Type Inference
Zod is designed to be as developer-friendly as possible. The goal is to eliminate duplicative type declarations. With Zod, you declare a validator...
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