TypeScript Needs to Emit Runtime Type Information
Please send a PR to add to this list. Even if it’s your own project and it has zero stars, you had to deal with this, so it goes on the list.
The Unfortunate List of Projects Working Around this Issue
Type Mapping Projects
Code Generation / External Tool Projects
Dear TS team,
Serialization and validation without a reflective type system just doesn’t work in the real world without endless boilerplate, or shiver, bespoke code generation from a schema file. The best solutions I could find are io-ts, zod, etc. The ever growing list above. The most courageous of us even resort to babel, but only to face the consequences. Someone even wrote a new language extending TypeScript to work around this. We have to declare our types in a round about library-bespoke way that is foreign to the uninitiated, and the libraries aren’t even able to support all the wonderful type magic you work so hard to provide.
This is a case, where we urge you to take a step back and holistically look at what TypeScript users have to do to in the majority of modern projects, and list them out in priority order. The decision of how to tackle serialization, and what actually has to be done to have TypeScript still work with it is at the top of the list. Even if you still don’t want to support reflection, please write a detailed doc, and put it in the official TypeScript documentation that explains how TypeScript users should tackle this problem or what library you recommend, so we don’t have endlessly reinvent the wheel.
Side note, please don’t solve this with decorators. A lot of us want to use interfaces. Decorators, like C# attributes are so coupling, and we can’t add them to types from other libraries. A higher order function that’s known to the compiler like:
typescript.generateRuntimeType<T>() with options for discriminators etc. means it would even work with external libs. Something like F# Type Providers, or C# Source Generators would also be welcome.
Last thing. If you do this, I will send you cake. If it’s in TypeScript 4.3, there will be ice-cream.
A humble disciple