News for hackers. Stuff that matters.
Re:Dependent Types and How to Get Rid of Them by wk_end on Tuesday November 11, 2025 @08:02PM (#45895160)
Like this:

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABA...

It's a bit of a hack, though - if you incorrectly implement myFunc so that, say, it returns a string even when x is true, it can violate the overloading assertions without any error or warning.

Re:Dependent Types and How to Get Rid of Them by codebje on Tuesday November 11, 2025 @09:45PM (#45895860)
Thanks! If anyone else is playing along, to get this to work with tsc I needed to use "--strict".

Being able to use a function along those lines in a type safe manner is still pretty nifty, even if you can't write it with type safety.