News for hackers. Stuff that matters.
Re:Things Go needs more than generics by rowanG077 on Monday October 04, 2021 @04:50AM (#28744532)
Unfortunately in any real world typescript or python the type checking is almost always partial. Which means it doesn't actually save you from these kind of errors.
Re:Things Go needs more than generics by cageface on Monday October 04, 2021 @05:07AM (#28744634)
I have not found this to be the case in Typescript code I've worked on. The main issue I've found with TS is stuff coming in from outside the system as JSON that doesn't conform to expected formats.
Re:Things Go needs more than generics by jakelazaroff on Monday October 04, 2021 @07:02AM (#28745200)
You can solve the JSON issue by validating that it deserializes to a known type at the point of ingress. I wrote a small library that I use in basically every project to help with that: https://www.npmjs.com/package/narrows
Re:Things Go needs more than generics by CryZe on Monday October 04, 2021 @05:24AM (#28744717)
One issue I've noticed is that indexing into a T[] array where T can't be undefined, results in the expression to be of type T, not T | undefined, despite an out of bounds index evaluating to undefined. I believe I've seen that they recently added a setting that changes this though.
Re:Things Go needs more than generics by cageface on Monday October 04, 2021 @05:39AM (#28744790)
A lot of statically typed languages leave array indexing as a loophole for convenience but yeah this can also be a source of errors.
Re:Things Go needs more than generics by andy_ppp on Monday October 04, 2021 @05:48AM (#28744845)
Consider using https://github.com/gcanti/io-ts to help with that...