Lurker News

Comments (191) 32 threads

Show all comments

Showing thread 21 of 32

soheilpro2 replies#
This is insane!

Just curios, are there real-world use cases for stuff like this?

williamdclt1 reply#
I could imagine working on very complex static JSON. You want to type-check selections and transformations on this JSON.

It's a very niche use-case, this is definitely more of an impressive showcase of the new Template Literal Types feature of TS :)

ricksharp#
You can import a json document directly into typescript and the entire document is a readonly constant type of the entire json object literal.

I've used this with a template JSON document that has an instance of all possible types in the runtime json.
Sometimes you might have to loosen the type slightly, but it works great for a quick start.

greencore#
You can embed any language interpreter into TypeScript and have that language syntaticaly checked by TS compiler.