GithubHelp home page GithubHelp logo

total-typescript / zod-tutorial Goto Github PK

View Code? Open in Web Editor NEW
539.0 539.0 158.0 271 KB

A crash course on Zod - a schema validation library for TypeScript

Home Page: https://totaltypescript.com

TypeScript 100.00%

zod-tutorial's People

Contributors

aljadan avatar arigunawan avatar mattpocock avatar pgsynatix avatar vojtaholik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zod-tutorial's Issues

fix: typo in the exercise title

Hi there,

Thank you very much for such great tutorials.
One small thing - there is a typo I think on the tutorial environment. Not sure where to mention it, maybe in this repo.

I guess it should be "Extract a type from a Parser Object"

image

Apologies if that's not the right place to mention this kind of things.
Thanks again for the amazing tutorial!

feat: add "or" solution to "07 union problem"


name: Feature request
about: Suggest an idea for this project
title: 'add "or" solution to "07 union problem"'

What is the motivation/use case for changing the behavior?

When discussing the possible solutions for exercise 07, it would be nice to include the use of "or" as a union alternative.

Describe the solution you'd like

Add the following as a third solution.

const Form = z.object({
  repoName: z.string(),
  privacyLevel: z.literal('private').or(z.literal('public')),
});

Suggest : add problem 15 for zod record

thanks for helpful tutorial :)
i had never know zod before i know this tutorial.
i think adding problem about zod's record is very helpful.

how do you think about my suggestion?

if you like i will add new problem for zod record

Exercise script always run all tests

I'm using

  • Windows 11
  • Node v16.15.1

When executed the exercise script, e.g. yarn exercise 01, it runs tests for all problems instead of the particular problem
image

✨ FR: Add a z.refine() example

I often happens in form validation that you have to compare two date fields, like from -> to, that is also possible in zod with refine as far as I remember.

fix: typo in exercise 08 problem description

Hi, Matt!

Really enjoying the tutorial and carefully reading every sentence 🤓

Should this read "... to pass any invalid email, phone number, or website url."? I reckon it should, since you speak about them in the video, but the inputs are singular.

Screenshot 2022-11-26 at 22 26 03

Keep on the great work!
Cheers

Exercise 14: incorrect return type passes

Currently both of these "solutions" pass exercise 14:

// correct
const genericFetch = <Schema extends z.ZodSchema>(
  url: string,
  schema: Schema
): Promise<z.infer<Schema>> => {
  return fetch(url)
    .then((res) => res.json())
    .then((result) => schema.parse(result));
};
// incorrect, doesn't return a promise
const genericFetch = <Schema extends z.ZodSchema>(
  url: string,
  schema: Schema
): z.infer<Schema> => {
  return fetch(url)
    .then((res) => res.json())
    .then((result) => schema.parse(result));
};

This is because the current test case checks the type of result, which awaits genericFetch, so it doesn't care if genericFetch returns a Promise or not.

I came up with two possibilities for a test case that catches this - I don't love either of these, maybe a TS Wizard could come up with something more elegant.

  1. Just check that genericFetch returns a promise of some sort
Expect<Equal<ReturnType<typeof genericFetch>, Promise<z.TypeOf<any>>>>
  1. Check the entire type of genericFetch
Expect<
  Equal<
    typeof genericFetch,
    <Schema extends z.ZodType<any, z.ZodTypeDef, any>>(
      url: string,
      schema: Schema
    ) => Promise<z.TypeOf<Schema>>
  >
>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.