total-typescript / zod-tutorial Goto Github PK
View Code? Open in Web Editor NEWA crash course on Zod - a schema validation library for TypeScript
Home Page: https://totaltypescript.com
A crash course on Zod - a schema validation library for TypeScript
Home Page: https://totaltypescript.com
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.github/workflows/renovate-checks.yml
package.json
zod ^3.21.4
@total-typescript/exercise-cli ^0.10.0
typescript ^5.4.5
vitest ^2.0.0
It's not following TDD flow, so at first, I think it's something wrong, then I checked the problem file, and It make sense.
where is tutorial video or document tutorial?
it seems a puzzle. I don't know how to start.
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
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"
Apologies if that's not the right place to mention this kind of things.
Thanks again for the amazing tutorial!
When discussing the possible solutions for exercise 07, it would be nice to include the use of "or" as a union alternative.
Add the following as a third solution.
const Form = z.object({
repoName: z.string(),
privacyLevel: z.literal('private').or(z.literal('public')),
});
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.
Expect<Equal<ReturnType<typeof genericFetch>, Promise<z.TypeOf<any>>>>
Expect<
Equal<
typeof genericFetch,
<Schema extends z.ZodType<any, z.ZodTypeDef, any>>(
url: string,
schema: Schema
) => Promise<z.TypeOf<Schema>>
>
>
Problem
Clicking "Start learning" at https://www.totaltypescript.com/tutorials/zod doesn't do anything
Expected behaviour
It should redirect to the video tutorials
Page : https://www.totaltypescript.com/tutorials/zod/optional/solution
some weird behavior on this page only, the screen flickers continuously on my large-resolution monitor but works fine for monitor with small resolution.
Screen Size: 1920px ร 1080px
I've attached video but unfortunately, my screen recorder couldn't capture the fps on which the screen is flickering.
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.
It works by using generic types.
const genericFetch = <T>(url: string, schema: z.ZodSchema<T>) => {
return fetch(url)
.then((res) => res.json())
.then((result) => schema.parse(result));
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.