I wish there would be an official TypeScript solution for this. I know there's a TypeScript goal that TypeScript types should not impact runtime behaviour, but I think converting arbitrary JSON from a file or network to a typed TypeScript object is such a common use case it needs a standardised solution. There's tens of libraries that try to solve this now in different ways, all working around this area where TypeScript doesn't try to help.
It reimplements the type system as… a stack based VM that expands the TS typedefs if needed at runtime?
I would use it if the risk factor wasn’t so high. I’m too scared of needing to maintain their crazy cool stuff to use it.
I would love Microsoft to build those APIs first party and officially support them.
EDIT:
> I know there's a TypeScript goal that TypeScript types should not impact runtime behaviour
This is why I’m rolling up my sleeves to build my own typescript-to-X tooling - it seems like no one is gonna do it for me, just the way I like — so I should make it easy for everyone to do it the way they like.
Sweetjs is unfortunately dead [0] for like 5 years now.
It also doesn't have any typescript awareness which is required to build this kind of functionality - you want to have static type introspection available in macros so you can generate code based on provided types.