zod
ts-reset
Our great sponsors
zod | ts-reset | |
---|---|---|
280 | 20 | |
29,771 | 7,529 | |
- | 3.1% | |
8.7 | 4.2 | |
6 days ago | 22 days ago | |
TypeScript | TypeScript | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
zod
-
Eloquent JavaScript 4th edition (2024)
It is (or should be) common practice to parse/validate any external data you depend on. You should be doing this for Javascript too. I find that the library https://zod.dev/ is quite helpful for this
-
How to build a blog with Astro
Astro uses Zod, a Typescript-first schema validation library, to type-check the collections' schemas. It helps validate data types when using collections inside UI components.
-
Translating zod errors with next-intl
When starting a new project with Next.js these days, next-intl and zod are my go to libraries for internationalization and schema validation, respectively. Of course, when using zod for client-facing validations I would like to translate potential error messages. The package zod-i18n can be used to achieve this for i18next, a popular alternative internationalization library. This means that by using this library as starting point one can quickly achieve zod translation with next-intl.
-
Htmx vs. React: A Complete Comparison – Semaphore
That is certainly one interpretation, but even then within most compile-time but not runtime-checked languages you can usually perform runtime checks. For example I've used Zod (https://zod.dev/) quite a bit in typescript to do runtime typechecks at the boundaries.
-
Creating Dynamic Forms with React, Typescript, React Hook Form and Zod
Learn more about Zod in the official documentation
-
Leveraging WordPress as a Headless CMS for Your Astro Website: A Comprehensive Guide
Zod for robust type validation, enhancing code reliability.
-
I write HTTP services in Go after 13 years (Mat Ryer, 2024)
So far I like the commonly used approach in the Typescript community best:
1. Create your Schema using https://zod.dev or https://github.com/sinclairzx81/typebox
2. Generate your Types from the schema. It's very simple to create partial or composite types, e.g. UpdateModel, InsertModels, Arrays of them, etc.
3. Most modern Frameworks have first class support for validation, like is a great example Fastify (with typebox). Just reuse your schema definition.
That is very easy, obvious and effective.
-
[React JS] I don't know a better way to handle Forms in React
But now, all those difficulties are gone since I found React Hook Form and zod.
- Squeezing more performance out of your Nextjs App
-
How to build a WhatsApp AI assistant
Zod, a popular typescript schema validation library that will let us define the shape of the payload sent to our background job.
ts-reset
-
Unleashing the Power of TypeScript: Improving Standard Library Types
TypeScript's standard library contains over 1,000 instances of the any type. There are many opportunities to improve the developer experience when working with strictly typed code. One solution to avoid having to fix the standard library yourself is to use the ts-reset library. It is easy to use and only needs to be imported once in your project.
-
Why doesn't TypeScript properly type Object.keys?
You might like TS Reset: https://github.com/total-typescript/ts-reset, which fixes this particular problem. I don't personally find it to be a big issue though.
Regarding runtime type checking, if you were to write something that can handle the total space of possible TS types, you would end up with incredibly complex machinery. It would be hard to make it perform, both in terms of speed and bundle size, and it would be hard to predict. I think Zod or perhaps https://arktype.io/ which target a reasonable subset are the only way to go.
-
Javascript vs typescript
https://github.com/total-typescript/ts-reset <-- this fixes the `(string | undefined)[]` issue and a few other quirks. Obviously it's annoying to need a library to fix quirks, but better than nothing.
-
Books/resources to improve TypeScript knowledge
Dude is an actual TypeScript wizard, his ts-reset package is a must have when dealing with JSON. He was featured in the VS Code day streams to show off some introductory TypeScript concepts and my big takeaway from that stream was this VS Code extension. Just stick // ^? on the line after something and it shows the type of the line above. Amazing with Prisma.
-
Typescript really hits the middle ground between extremely rigid statically typed languages on one extreme and no types at all dynamic languages on another extreme. Best type system
Personally I quite like ts-reset to "fix" some of the std lib types - JSON.parse will now return unknown. It's then up to you to decide how you wish to parse that unknown (zod, runtypes, io-ts are all reasonable options here). Won't ever be done by TS itself, as generating runtime code is a non-goal for the project.
-
Free Next.js Boilerplate for ⚡️High-Performance⚡️ Enterprise Apps
🛠️ Extremely strict TypeScript - With ts-reset library for ultimate type safety
-
A 'CSS reset' for TypeScript, improving types for common JavaScript API's
For reference, I've suggested such info could be mentioned in the project [0] and author sees as "too niche".
Reading https://github.com/total-typescript/ts-reset/blob/main/src/e..., I'm more confused than before. The generic NonFalsy[] looks to me like it should evaluate to never[] if the entire array is false, and to T[] (the original array type, not narrowed) otherwise. But I can see that the test case demonstrates that it works. What am I missing?
-
JSTools Weekly — ✨2023#8: TS-Reset: A ‘CSS reset’ For TS, Improving JS Types
ts-reset: A 'CSS reset' for TypeScript, improving types for common JavaScript API's
What are some alternatives?
class-validator - Decorator-based property validation for classes.
joi - The most powerful data validation library for JS [Moved to: https://github.com/sideway/joi]
Yup - Dead simple Object schema validation
typebox - Json Schema Type Builder with Static Type Resolution for TypeScript
ajv - The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
io-ts - Runtime type system for IO decoding/encoding
Superstruct - A simple and composable way to validate data in JavaScript (and TypeScript).
class-transformer - Decorator-based transformation, serialization, and deserialization between objects and classes.
runtypes - Runtime validation for static types
react-hook-form - 📋 React Hooks for form state management and validation (Web + React Native)
TypeScript - TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
zod-to-json-schema - Converts Zod schemas to Json schemas