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.

Have types exports on generated file?

See original GitHub issue

Feature description

The generated file only contains the schemas. I would have no problemas for my small files to have the export type MyType = z.infer<typeof myTypeSchema>. Looks like I have to add them manually to the generated file.

Input

export type MyType = z.number();

Output

export const myTypeSchema = z.number();
export type MyType = z.infer<typeof myTypeSchema>;

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
SrBrahmacommented, May 30, 2022

Hi!

Typescript is smart!

image

Even using infer, it keeps the JSDoc comments from the schema!

0reactions
fabien0102commented, Jun 1, 2022

Ah ok, now I get your usecase! you are mutating the generated zod schema! If this is the case, this was not really the intented usage (I’m always happy to be challenged). The idea was to keep the generated file as source of truth and sync with the typescript definition and import/extends the schemas in a separate file. But regarding your screenshot, I get why this is probably not possible in your case.

Looks like I have to add them manually to the generated file.

But now everything make sense 😅

Anyway, this should not be too hard adding an option to generate those infer, we just need to make sure to not have any name conflicts when the types are recursive (https://github.com/colinhacks/zod#recursive-types)

Read more comments on GitHub >

github_iconTop Results From Across the Web

export type * from 'somewhere' #48508 - GitHub
We have a file that only contains type annotations (https://github.com/babel/babel/blob/main/packages/babel-types/src/ast-types/generated/index.
Read more >
Export all interfaces/types from one file in TypeScript project
You can export them directly if you don't need to use them. export * from '../foo/bar';. Or if you need to export only...
Read more >
Documentation - Modules - TypeScript
Modules are declarative; the relationships between modules are specified in terms of imports and exports at the file level. Modules import one another...
Read more >
Generating a File to Export - Oracle Help Center
Generating a File to Export. Click Import/Export. On the Import/Export Request Parameters page, select the Export option. In the Hierarchy Selection area, ...
Read more >
File format options for PDF export - Adobe Support
Generates tags for files that are not already tagged, such as PDFs created using Acrobat 4.0 or earlier. If this option is not...
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