-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- we can configure if Maybe represents nullable, optional, or both. - we can define which generic types to use as Maybe (e.g. Maybe, InputMaybe, etc). Can be multiple. - when ts-to-zod encounters a generic type in the list of "Maybe"s, it skips the schema generation for them. - when it encounters them as being used, it makes a call to `maybe()` function. - the `maybe` function is defined depending on the nullable/optional config. This is useful to work in conjunction with other codegen tools, like graphql codegens. e.g. ```ts // config /** * ts-to-zod configuration. * * @type {import("./src/config").TsToZodConfig} */ module.exports = [ { name: "example", input: "example/heros.ts", output: "example/heros.zod.ts", maybeTypeNames: ["Maybe"], } ]; // input export type Maybe<T> = T | null | "whatever really"; // this is actually ignored export interface Superman { age: number; aliases: Maybe<string[]>; } // output export const maybe = <T extends z.ZodTypeAny>(schema: T) => { return schema.nullable(); }; export const supermanSchema = z.object({ age: z.number(), alias: maybe(z.array(z.string())) }); ``` Configuration: By default, this feature is turned off. When adding the list of type names to be considered 'Maybe's, we turn it on. Maybe is nullable and optional by default, unless specified otherwise. We can set this in CLI options... - `maybeOptional`: boolean, defaults to true - `maybeNullable`: boolean, defaults to true - `maybeTypeName`: string, multiple. List of type names. …as well as in the ts-to-zod config file. - `maybeOptional`: boolean - `maybeNullable`: boolean - `maybeTypeNames`: string[]. list of type names.
- Loading branch information
Showing
15 changed files
with
465 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ dist | |
build | ||
lib | ||
.vscode | ||
.idea | ||
.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.DS_Store | ||
node_modules | ||
coverage | ||
.nyc_output | ||
dist | ||
build | ||
lib | ||
.vscode | ||
.idea | ||
.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.