But I hadn't appreciated the difference in difficulty between an unsound type system like TS and Scala's type system...
I guess I've taken the formalism that underlies Scala's type system (e.g. the academic research behind dotty) as a given/for granted, but you're likely right, that TS can move faster because it doesn't need/have that level of rigor.
Thanks!
Did you mean "behind"?
The trend is pretty clear: dynamically typed languages are disappearing and all the popular modern languages are statically typed with type inference.
Most dynamically typed languages are busy adding static safety through gradual or opt-in typing, but you don't see the other way around.
Javascript will probably be the last major dynamically typed language we ever had to use.
It does seems that all the dynamic languages are learning what the systems people knew in the 70s: for the Enterprise, correctness counts.
A happy v1 is only 10% of the story... Getting to v225.5, warts and all, is just something else.
Yeah, it is. At the very least, I know that function parameters are bivariant, which isn't sound:
function foo(callback: (obj: Object) => void) {
callback("not a bool");
}
function main() {
foo(function (bool: Boolean) {
if (bool) window.console.log("!");
});
}
This compiles without a type error but ends up assigning a string to a parameter of type bool.Since TS 2.6, if you enable all the optional "strict" mode checks than TypeScript does complain about that code.
I see no disadvantage in those checks, e.g. "strictFunctionTypes", being optional, since you can always make them mandatory for your own project(s).
To test it:
- Go to the TS Playground at https://www.typescriptlang.org/play/
- Enter the above code
- Select "Options" and enable at least "strictFunctionTypes"
> TypeScript 2.6 introduces a new strict checking flag, --strictFunctionTypes.
> The --strictFunctionTypes switch is part of the --strict family of switches, meaning that it defaults to on in --strict mode.
> Under --strictFunctionTypes function type parameter positions are checked contravariantly instead of bivariantly.
> ...(etc.)
If you enter any random TS project today, odds are it isn't using that switch, and enabling the switch will lead you down a month long rabbit-hole of fixing cascading type errors.
When you want the whole system to actually deeply rely on the static type system, it needs to be much more robust, and that takes a lot of effort.
I'm not trying to minimize what the TypeScript folks are doing — it's a really nice, well-designed language. But the complexity required to evolve an optionally-typed language is closer to that of a dynamically-typed one than a statically-typed one.