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…
Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs
11–20 of 80 posts
Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs
#12Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs
#13Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs
#14Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs
#15Cool, 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 out…
Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs
#16Cool, but I assume not great for performance? Probably better to just stick with codegen
Assuming you mean compiler/editor performance then yes I assume this wrecks it. Shouldn't matter for runtime though.
Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs
#17Cool, 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 out…
If your codegen is introducing runtime overhead you should use a different codegen.
> type inference in VSCode seemed reasonably fast with the toy examples I was playing with
It usually is. It can become a problem in a real project that has a lot of stuff going on, though.
Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs
#18 const schema = proto`
syntax = "proto3";
message Person { ... }
`;
type Person = typeof schema['Person'];
And you could get built-in schema validation with a sophisticated enough type definition for `proto`, nice syntax highlighting in many tools with a nested grammar.We would love to see this feature in TypeScript to be able to have type-safe template in lit-html without an external tool.
The issue hasn't seen much activity lately, but it would be good to highlight this library as another use case.
Re: Show HN: Zero-codegen, no-compile TypeScript type inference from Protobufs
#19The 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…