News for hackers. Stuff that matters.
Re:TypeScript please give us types by cornstalks on Friday July 07, 2023 @04:48PM (#36638102)
> > TypeScript Needs to Emit Runtime Type Information

> This is not possible at all because TypeScript is a compiler.

Sorry, can you clarify? Many compilers exist in other languages that support RTTI, so it's not clear to me what you mean by this.

Re:TypeScript please give us types by paxys on Friday July 07, 2023 @04:57PM (#36638205)
There are plenty of projects that do the same for TypeScript (e.g. https://github.com/typescript-rtti/typescript-rtti) and plenty that support some kind of runtime reflection, and overall emitting TS type information at compile time in some readable format is a pretty trivial problem to solve. The complicated part is on the other side – what do you do with this information? How do you get JavaScript engines to understand it?
Re:TypeScript please give us types by wvenable on Friday July 07, 2023 @05:01PM (#36638241)
You don't get JavaScript engines to understand it. You use a library.
Re:TypeScript please give us types by paxys on Friday July 07, 2023 @05:30PM (#36638586)
So then...exactly how it is done today? TypeScript provides an API to get type info at compile time. Libraries write plugins to consume this type info and use it for custom runtime validation. What changes in this new world?
Re:TypeScript please give us types by code_biologist on Saturday July 08, 2023 @02:49AM (#36641990)
> So then...exactly how it is done today? TypeScript provides an API to get type info at compile time.

That's exactly it, it doesn't. That project you linked (typescript-rtti) mentions in the README that you must install and use it via ttypescript, a typescript wrapper that patches the compilation process to expose compilation details to plugins. Except that plugin API is unofficial and changes break the ecosystem built on it. For example, ttypescript doesn't work for TS 5 and the dev doesn't want to spend time on it. ts-patch has stepped in to provide a source transformer API for TS 5.

There's no way I can recommend libraries like typescript-rtti in commercial projects until something changes. I hope the ts-patch folks don't burn out.