Our great sponsors
-
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.
You probably don’t want that throughout your entire codebase. It’s a lot of overhead. Where you do want it (at API/user input/network etc boundaries), you can use something like Zod[1] or similar to define your type guards and then infer the static types from there.
> There's no native typescript runtime.
A proposal was actually floated recently to grandfather in TypeScript-like annotations[1]. It would be ignored by the runtime and treated purely as a comment, and would be optional. This is what native runtime support for TypeScript would look like. Not sure if it will ever gain official support in the language though.
> it doesn't enforce types at runtime, only at build time
Runtime type "enforcement" is just your program breaking, for example "undefined is not a function". Well, I guess it isn't so simple, because JS does a lot of implicit type translation behind the scenes, like helpfully converting "123" to 123. It would be possible to "enforce" types at runtime by turning off that language feature in certain situations, but I don't think it will happen, for back-compat reasons.
Related posts
- React how to get which props does a children need
- Zod — валидация и вывод типов на основании схемы данных
- You can’t run away from runtime errors using TypeScript
- Epic Next JS 14 Tutorial Part 4: How To Handle Login And Authentication in Next.js
- Error handling in our form component for the NextAuth CredentialsProvider