Re:The memory safety problem isn't bad coders
by pas on Tuesday February 12, 2019 @02:31PM
(#19146679)
It's not the fall, but the stop that kills you. So in case of TS we don't know what was the intent.
Maybe it was this.
function suffixWith10(s: string) { return s + 10; }
But if the intent can be discovered by analysis of usages of the variable later in the code, then TS will scream loudly.
Re:The memory safety problem isn't bad coders
by chc on Tuesday February 12, 2019 @02:18PM
(#19146545)
This is more of a knock against the compromises TypeScript's wacky type system has to make for JavaScript compatibility than anything else. It's not possible in a language that was really designed for strong static typing like Haskell or Rust.
You could imagine it having built-in rules for JS' coercions:
Maybe your snippet is provocative to some people, but in real code it would quickly fail once you actually use `bar` and were wrong about your assumptions.At which point it's similar to languages with `Int + Float -> Float` and `Short + Long -> Long` in that perhaps you wish those operators weren't defined but it's at least consistent. And you'd find the error once you've passed those results to a function that expected Int or Short.