Google tried to do that with Dart, and failed. In fairness Dart 1 was much worse than Dart 2… So maybe that was a good thing because there’s no way they’d have been able to improve Dart as much as they have if it was part of the web.
Yes and no. Wasm has no “standard library” so if you wanted to use Dates, your wasm would need to have its own implemation bundled for when the user visits the page. Ditto for everything else including string support! As you can imagine having to ship all this basic functionality can bloat the wasm and slow page loads.
You also can’t fully escape JS, as the only way wasm can interact with the page & browser are through the JS functions you write and make available to your wasm. I suppose you could take advantage of this to not have to ship your own standard library & use the JS Date implementation, but at that point why not just use JS?
Wasm has strengths but it’s not suitable for replacing JS for everyday websites.
Let’s not get ahead of ourselves. Typescript has a decent type system, but it’s hardly state of the art. It’s impressive how they’ve managed to mostly corral JavaScript into something much more sane, but at the end of the day it still suffers greatly from the limitations of JavaScript. They’ve essentially retrofitted some type theory onto JavaScript to make it possible to express JavaScript nonsense in the type system, but there’s plenty of things that would have been designed differently had they been making something from scratch. Not to mention that the type system is unsound by design, which by itself puts it behind languages designed from the ground up to have sound type systems.
There’s many, many things missing from the type system, like higher-kinded types, type-driven deriving/codegen, generalized algebraic data types (aka GADTs), type families (and relatedly, associated types), existentially-quantified types, and much more.
You don’t need to use TS to avoid common issues. If you add an empty object to an empty array and expect a meaningful result, the problem sits in front of the keyboard.
Sure, discipline can prevent some errors. But it’s always possible to run into wrong type assumptions, and I’d say type coercion and null/undefined access make up a fairly large percentage of non-logic errors. You can entirely prevent those using Typescript, which is why it’s so useful.
Static type analysis is always a good idea if you’re writing more than a couple lines. IMO Python is the worst offender with its kwargs etc. - discoverability and testability is just so bad if you’re following common Python idioms.
Can we start a new web with a better language/platform already?
Google tried to do that with Dart, and failed. In fairness Dart 1 was much worse than Dart 2… So maybe that was a good thing because there’s no way they’d have been able to improve Dart as much as they have if it was part of the web.
For dates there finally is something better anyway: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal
There’s wasm if you need to target browsers.
Yes and no. Wasm has no “standard library” so if you wanted to use Dates, your wasm would need to have its own implemation bundled for when the user visits the page. Ditto for everything else including string support! As you can imagine having to ship all this basic functionality can bloat the wasm and slow page loads.
You also can’t fully escape JS, as the only way wasm can interact with the page & browser are through the JS functions you write and make available to your wasm. I suppose you could take advantage of this to not have to ship your own standard library & use the JS Date implementation, but at that point why not just use JS?
Wasm has strengths but it’s not suitable for replacing JS for everyday websites.
Why? Why not improve JS (e.g. with Temporal), especially given how excellent Typescript is?
I wouldn’t call typescript excellent, if I did it would be on a very low standard.
It unquestionably is excellent. Can you name another language in common use with a type system that’s close to the expressiveness of Typescript?
Let’s not get ahead of ourselves. Typescript has a decent type system, but it’s hardly state of the art. It’s impressive how they’ve managed to mostly corral JavaScript into something much more sane, but at the end of the day it still suffers greatly from the limitations of JavaScript. They’ve essentially retrofitted some type theory onto JavaScript to make it possible to express JavaScript nonsense in the type system, but there’s plenty of things that would have been designed differently had they been making something from scratch. Not to mention that the type system is unsound by design, which by itself puts it behind languages designed from the ground up to have sound type systems.
There’s many, many things missing from the type system, like higher-kinded types, type-driven deriving/codegen, generalized algebraic data types (aka GADTs), type families (and relatedly, associated types), existentially-quantified types, and much more.
JS is a lost cause.
How? It’s easy not to run into the common issues by using TS. What’s so bad about it that we should throw away the existing ecosystem?
Please give arguments instead of platitudes.
You don’t need to use TS to avoid common issues. If you add an empty object to an empty array and expect a meaningful result, the problem sits in front of the keyboard.
Sure, discipline can prevent some errors. But it’s always possible to run into wrong type assumptions, and I’d say type coercion and null/undefined access make up a fairly large percentage of non-logic errors. You can entirely prevent those using Typescript, which is why it’s so useful.
Static type analysis is always a good idea if you’re writing more than a couple lines. IMO Python is the worst offender with its
kwargs
etc. - discoverability and testability is just so bad if you’re following common Python idioms.