4 ms·
TypeScript has a comparatively easier job because the type system is unsound. They can add new type features without needing to be paranoid about a hole in the
by munificent 9y ago
TypeScript has a comparatively easier job because the type system is unsound. They can add new type features without needing to be paranoid about a hole in the system or a usability pitfall because the tools don't rely on types for correctness or optimization, and because users can easily cast to "any" or otherwise work around an annoyance.
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.
- naasking 9y agoIs it actually unsound if you perform no casting? That seems to be a more interesting property, because then the additions they're making still have to mesh cohesively.
- raquo 9y agoYes, look at how it deals with type param variance for example. It doesn't.
- munificent 9y ago> Is it actually unsound if you perform no casting? 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.
- ItsMe000001 9y agoI'm a Flow user rather than TS (and Flow complains about that code out of the box), but you are not telling us all: 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/ https://www.typescriptlang.org/play/ - Enter the above code - Select "Options" and enable at least "strictFunctionTypes"
- naasking 9y agoIs that option documented somewhere? I imagine there are some tradeoffs with enabling it.
- ItsMe000001 9y agohttps://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-6.html https://www.typescriptlang.org/docs/handbook/release-notes/t... > 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.)
- naasking 9y agoContravariance then, right. Thanks! I haven't gotten into Typescript yet, and at this point it looks fairly large and a little daunting, so this is helpful.
- tomerbd 9y agoAnd this project is super interesting: https://1c.wizawu.com/#/whatis https://1c.wizawu.com/#/whatis Use TypeScript on JVM with both NPM and Maven dependencies
- ihsw2 9y agoTradeoffs? It might frustrate some people more accustomed to JS' loose type system.
- coryfklein 9y agoThe major tradeoff, IMO, is that it is even toggle-able at all, let alone being a feature switch that is enabled by default. 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.
- stephen 9y agoGood point; I've mused before that dynamic languages will always be a ~generation ahead of static languages, due to what you point out, that type systems are hard, and very few people start working on a new type system as their hobby project (vs. hacking out a new syntax with an interpreter). 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!
- hota_mazi 9y ago> I've mused before that dynamic languages will always be a ~generation ahead of static language 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.
- bonesss 9y ago> dynamically typed languages are disappearing and all the popular modern languages are statically typed with type inference 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.