Skip to content

feat: support standard built-in objects#122

Open
NexZhu wants to merge 2 commits intofabien0102:mainfrom
daotl:feat/built-in-objects
Open

feat: support standard built-in objects#122
NexZhu wants to merge 2 commits intofabien0102:mainfrom
daotl:feat/built-in-objects

Conversation

@NexZhu
Copy link
Contributor

@NexZhu NexZhu commented Mar 15, 2023

Why

Browser and Node.js both provide many standard built-in objects such as Error Int8Array BigInt etc.

Before this PR, if types are using these built-in objects, ts-to-zod will fail with missing dependencies, this PR support built-in objects by using Zod's z.instanceof method.

For example:

export interface Person {
  photo?: Uint8Array | null;
}

will generate:

const uint8ArraySchema = z.instanceof(Uint8Array);

export const personSchema = z.object({
  photo: uint8ArraySchema.optional().nullable(),
});

The list of standard built-in objects is from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects

@NexZhu
Copy link
Contributor Author

NexZhu commented Mar 15, 2023

@fabien0102 Please check this out too when you have time, so I can open further improvement PRs after this get merged, thanks! 😄

@fabien0102
Copy link
Owner

Sorry, I totally missed this PR 🫣 I will have a look next week! Nice job 👌

@schiller-manuel
Copy link
Collaborator

can you rebase this so this can get merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants