Type-Safe Printf() in TypeScript
typescriptlang.org
Type-Safe Printf() in TypeScript
1–10 of 82 posts
Re: Type-Safe Printf() in TypeScript
#2There is a way to make this easier to extend, though: https://tsplay.dev/WGbEXm
Can't tell off the top of my head if there are any disadvantages to this approach though.
Re: Type-Safe Printf() in TypeScript
#3Re: Type-Safe Printf() in TypeScript
#4Except missing the pesky runtime implementation. We don't need though, right? As long as the types say it's right.
Re: Type-Safe Printf() in TypeScript
#5Except missing the pesky runtime implementation. We don't need though, right? As long as the types say it's right.
The function implementation itself isn’t that interesting, or “pesky” to be honest
Re: Type-Safe Printf() in TypeScript
#6Recently though, I've been wondering whether advanced type system stuff is the right approach. It usually becomes pretty complicated, like another language on top of the regular language. Maybe it would be easier to have some kind of framework for compiler plugins that do extra checks. Something that would make it easy to check format strings or enforce rules on custom attributes, like Linux's sparse does, using plain imperative code that's readable to the average dev. Large projects would have an extra directory for compile time checks in addition to the tests directory they have now.
But I haven't seen any language community do something like that. What am I missing?
Re: Type-Safe Printf() in TypeScript
#7you can also use typescript-eslint/restrict-template-expressions if you find yourself running into problems with that
https://typescript-eslint.io/rules/restrict-template-express...
Re: Type-Safe Printf() in TypeScript
#8Except missing the pesky runtime implementation. We don't need though, right? As long as the types say it's right.
Re: Type-Safe Printf() in TypeScript
#9Reminds me of Idris: https://gist.github.com/chrisdone/672efcd784528b7d0b7e17ad9c... Recently though, I've been wondering whether advanced type system stuff is the right approach. It usually becomes pretty complicated, like another language on top of the regular language. Maybe it would be easier to have some kind of framework for compiler plugins that do extra checks. Something that would make it easy to check forma…