🔧 ProgrammierungRequest lifecycle: HandlerMapping HandlerAdapter resolvers(16.09.2026 um 00:08 Uhr)
🔧 ProgrammierungChapter 1 - The Funkiest of All Machines(16.09.2026 um 00:13 Uhr)
🔧 AI Nachrichten President Trump Called Nvidia’s Jensen Huang About A.I. Slowdown(15.09.2026 um 23:45 Uhr)
🔧 AI Nachrichten Google’s Simulated Fruit Fly Brain Did Not Write This Article(16.09.2026 um 00:00 Uhr)
🔧 ProgrammierungRequest lifecycle: HandlerMapping HandlerAdapter resolvers(16.09.2026 um 00:08 Uhr)
🔧 ProgrammierungChapter 1 - The Funkiest of All Machines(16.09.2026 um 00:13 Uhr)
🔧 AI Nachrichten President Trump Called Nvidia’s Jensen Huang About A.I. Slowdown(15.09.2026 um 23:45 Uhr)
🔧 AI Nachrichten Google’s Simulated Fruit Fly Brain Did Not Write This Article(16.09.2026 um 00:00 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 16 Min Lesezeit
0

JavaScript schema library from the Future 🧬

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

, , , , and more. Also, even though this is slightly different, validation libraries like , and others also stand really close.






Is ReScript Schema faster than all of them?



Yes. It's ~100 times faster than or ). But often, besides validation, you want to transform data incoming to your system, and here, ReScript Schema overperforms any solution existing in the JavaScript ecosystem.






What's ReScript? Isn't the library for JavaScript/TypeScript?



under the hood. You needn't worry about the code's dangerous execution, but some environments, like Cloudflare Workers, won't work. In 99% of cases, you don't need to be concerned about this. I just think it's my duty as a creator to let you know about the 1% beforehand.





What's the plan?



I'm going to provide an overview of the basic ReScript Schema API and mental model. Then, we'll discuss what makes it stand out from millions of similar libraries (and this is not only performance). I'll also look at some more advanced use cases and discuss the ecosystem, performance, and where it stands with other libraries.



I hope you'll enjoy it. 😊




Follow me on from Zod's docs. If you're curious about when and why you need to parse data in your application, let me know in the comments. I can write a big article about it, but for now, I assume you are already familiar with the concept.



Let's finally take a look at the code. I'll go with the TypeScript example first, so it's more familiar for most readers. Everything starts with defining a schema of the data you expect:




CODE
import * as S from "rescript-schema";

const filmSchema = S.schema({
id: S.number,
title: S.string,
tags: S.array(S.string),
rating: S.union(["G", "PG", "PG13", "R"])
})






The schema here is like a type definition that exists in runtime. If you hover over the filmSchema, you'll see the following type:




CODE
S.Schema<{
id: number;
title: string;
tags: string[];
rating: "G" | "PG" | "PG13" | "R";
}>






This is a Schema type that inferred the film object definition. I recommend extracting its value into its own type. This way, you'll have the schema as the source of truth and the Film type always matching the schema:




CODE
type Film = S.Output<typeof filmSchema>






After we've defined our Film type using the schema, we can parse unknown data entering our application to guarantee that it matches what we expect:




CODE
S.parseOrThrow(
{
id: 1,
title: "My first film",
tags: ["Loved"],
rating: "S",
},
filmSchema,
);
//? Throws RescriptSchemaError with message `Failed parsing at ["rating"]. Reason: Expected "G" | "PG" | "PG13" | "R", received "S"`

S.parseOrThrow(validDataWithUnknownType, filmSchema)
//? Returns value of the Film type


// If you don't want to throw, you can wrap the operations in S.safe and get S.Result as a return value
S.safe(() => S.parseOrThrow(data, filmSchema))






Done! We have valid data here 🙌



Some experienced users may have noticed that the API is similar to one, the parser will perform in the most optimized way. I personally have seen this kind of DX only in

, it's getting impossible to extract the film type from the schema (even though it can infer it). But there's a built-in way to prevent boilerplate code in ReScript. You can use ReScript Schema PPX to generate schemas for your types automatically. Just annotate them with @schema attribute.




CODE
@schema
type rating =
| @as("G") GeneralAudiences
| @as("PG") ParentalGuidanceSuggested
| @as("PG13") ParentalStronglyCautioned
| @as("R") Restricted
@schema
type film = {
id: float,
title: string,
tags: array<string>,
rating: rating,
}






Does the rating type look scary to you? Don't worry, this is a ReScript and does and maybe even faster 😎






100 Operations



If you want the best possible performance or the built-in operations don't cover your specific use case, you can use S.compile to create fine-tuned operation functions.




CODE
const operation = S.compile(S.string, "Any", "Assert", "Async");
//? (input: unknown) => Promise<void>

await operation("Hello world!");






In the example above, we've created an async assert operation, which is not available by default.



With the API, you can get 100 different operation combinations, each of which might make sense for your specific use case. This is like to confirm yourself. If you see and the people behind it for allowing me to write very performant and safe code.



Talking about , which combines the DX of . I also built many powerful tools around ReScript Schema, but I have to admit that I haven't added TS support yet. Let me know if you find something interesting to use, and I'll do this asap 😁



Also, ReScript Schema supports , , and X follow 🙏



Let's see how the future of schema libraries will turn out. Maybe I'll rename ReScript Schema to something dope and become more popular than Zod? Cheers 😁

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Protect Kubernetes Services with OAuth2 Proxy, Gateway API, Traefik, and Pocket ID
1 Quelle
Request lifecycle: HandlerMapping HandlerAdapter resolvers
1 Quelle
The best n8n fix I found this month was boring: lower your agent concurrency settings before touching the prompt
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten JavaScript schema library from the Future 🧬

Thematisch verwandte Begriffe: JavaScript, schema, library, from · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...