Live data from Hacker News

Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs

github.com

1–10 of 80 posts

Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs

#4
The fact that the source is so small is wild. I would have expected a huge convoluted parsing library implemented in types.

On the other hand, the fact that this is even possible is more wild. Instead of replacing JS with a proper statically-typed language, we're spending all this effort turning a preprocessor's type system into a turing-complete metalanguage. Pretty soon we'll be able to compile TypeScript entirely using types.

Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs

#5

Cool, but I assume not great for performance? Probably better to just stick with codegen

You're right that IDE/dev-time performance might be slower than using generated types since this relies on "dynamic" TypeScript inference rather than static codegen'd types.

That said, depending on how your codegen works and how you're using protos at runtime, this approach might actually be faster at runtime. Types are stripped at compile-time and there’s no generated class or constructor logic — in the compiled output, you're left with plain JS objects which potentially avoids the serialization or class overhead that some proto codegen tools introduce.

(FWIW, type inference in VSCode seemed reasonably fast with the toy examples I was playing with)

Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs

#6
post #4

The fact that the source is so small is wild. I would have expected a huge convoluted parsing library implemented in types. On the other hand, the fact that this is even possible is more wild. Instead of replacing JS with a proper statically-typed language, we're spending all this effort turning a preprocessor's type system into a turing-complete metalanguage. Pretty soon we'll be able to compile TypeScript entirely…

I would have written a shorter source, but I did not have the time.

Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs

#7
post #4

The fact that the source is so small is wild. I would have expected a huge convoluted parsing library implemented in types. On the other hand, the fact that this is even possible is more wild. Instead of replacing JS with a proper statically-typed language, we're spending all this effort turning a preprocessor's type system into a turing-complete metalanguage. Pretty soon we'll be able to compile TypeScript entirely…

Or even run doom in TypeScript's type system!

Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs

#8
It's always impressive how far people can take TypeScript and even build parsers with it. But this is limited to inlined string literals and cannot read files (a TS limitation).

I wonder if the author has a use case in mind for this that I don't see. Like if you are only using TS, what's the point of protobuf? If you are exchanging data with programs written in other languages why avoid the protobuf tooling that you need anyway?

Maybe this is just a fun toy project to write a parser in TS?

Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs

#9
post #7
post #4

The fact that the source is so small is wild. I would have expected a huge convoluted parsing library implemented in types. On the other hand, the fact that this is even possible is more wild. Instead of replacing JS with a proper statically-typed language, we're spending all this effort turning a preprocessor's type system into a turing-complete metalanguage. Pretty soon we'll be able to compile TypeScript entirely…

Or even run doom in TypeScript's type system!

Prepare to have your mind blown:

https://www.youtube.com/watch?v=0mCsluv5FXA

Post reply on HN