TypeScript Decoders and why they Matter if you care about robust code

This page summarizes the projects mentioned and recommended in the original post on /r/programming

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • io-ts

    Runtime type system for IO decoding/encoding

  • I don't think "validator" is the right word though - validator implies a thing that tells you whether the data is valid or not (boolean). These "decoders" generally take it a step further, they provide the narrowed type (if the decode is successful). io-ts calls the data structure a "codec", because it can be used to both encode and decode data.

  • typescript-json-decoder

    Json Decoder for Typescript

  • I hadn't heard of Zod! Very similar indeed, I will have to check it out. If you're wondering exactly how it works, check out this earlier piece I wrote.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • zod

    TypeScript-first schema validation with static type inference

  • Neat. I think Zod is the best known solution to this problem but it doesn't work in pure Typescript. This looks like it might which would be great but I also don't see how it could work...

  • graphql-code-generator

    A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.

  • If you don't want any runtime overhead, you should just use a TS types generator or some compile time magic to call your api route functions directly. For GraphQL, there is the amazing graphql-code-generator which generates fully typed functions you can call on the frontend from your schema.

  • typescript-needs-types

    TypeScript please give us types.

  • Lol, look what I just found, someone created a whole petition about adding runtime type information (which would make a lot of use libraries redundant): https://www.typescriptneedstypes.com/

  • TypeScript

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

  • Yeah I see what you mean. Indeed all the typing information evaporates after the compilation but I really don't get why it has to be this way to the very end. If you read the ticket https://github.com/microsoft/TypeScript/issues/3628 nowhere the TS team gave any compelling explanation, and it is crazy how many approaches people came up with on how to address it.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts