Type-Safe Printf() in TypeScript
51–60 of 82 posts
Re: Type-Safe Printf() in TypeScript
#52I've been kind of curious why tricks like this aren't used more to make sql and such. Heck, you could do similar tricks for shell execution. Or any general "string that is parseable." Seems we always take the route of not parsing the string as much as we can?
Re: Type-Safe Printf() in TypeScript
#53Earlier quoted context omitted.
Go's type system is inferior to Typescript's in every possible way. About the only saving grace it has is that it didn't start out in a non-typesafe ecosystem, but most of those issues have been alleviated in Typescript for years. At this point, folks are seeing how far they can push the Typescript type system because it's capable of expressing so, so much more with its types than is seen typically(including in most…
Typescript typing isn't even required, so your argument just fell apart.
Re: Type-Safe Printf() in TypeScript
#54Am I missing something? This is just a toy implementation of a function prototype, that only includes integers and strings?
It's just a cool use of some of typescript's more advanced features that many developers probably don't use on a day-to-day basis (likely for good reason, as other comments have pointed out!)
Re: Type-Safe Printf() in TypeScript
#55Earlier quoted context omitted.
> If JavaScript was a failure By almost any reasonable measure it is one of the strongest candidates for “biggest success ever as a programming language”. Sure, you can argue that the reasons for that aren’t mainly language design related, but it is absolutely not anything like a failure.
It only succeeded because it literally couldn’t fail. It had plenty of competitors and all of them had one critical flaw: not being built in to the browser.
Re: Type-Safe Printf() in TypeScript
#56I've been kind of curious why tricks like this aren't used more to make sql and such. Heck, you could do similar tricks for shell execution. Or any general "string that is parseable." Seems we always take the route of not parsing the string as much as we can?
There are a bunch of more practical takes that codegen types from your database and generate types for your queries, eg: https://github.com/adelsz/pgtyped
To me the second approach seems much more pragmatic because you don’t need to run a SQL parser in your typechecker interpreter on every build
Re: Type-Safe Printf() in TypeScript
#57Earlier quoted context omitted.
But the Go type system is pathetic in comparison to Typescript.
Typescript typing isn't even required, so your argument just fell apart.
Re: Type-Safe Printf() in TypeScript
#58Am I missing something? This is just a toy implementation of a function prototype, that only includes integers and strings?
As a general rule, if something is on the HN homepage and you find yourself asking "am I missing something?", the answer is almost by definition "yes" :) It's just a cool use of some of typescript's more advanced features that many developers probably don't use on a day-to-day basis (likely for good reason, as other comments have pointed out!)
Meanwhile, the HN homepage is not some carefully guarded display of exceptional merit, and no serious "hacker" would take the things posted here to be above reproach.
Re: Type-Safe Printf() in TypeScript
#59Word of warning: the typescript compiler is not a particularly fast evaluator of recursive list manipulation programs, which is what these kinds of types are. They’re great in small doses where you really need them, but overuse or widespread use of complex types will make your build slower. It’s much better to avoid generics or mapped types if you can. The typings for a tagged template literal (without digit format s…
Re: Type-Safe Printf() in TypeScript
#60Please don't adopt this.