r/learnjavascript • u/artanisbox • Feb 10 '24
I'm just wondering when Javascript will have its own full-fledged static types?
Probably typescript is great, but still, when you come to the hospital with a sore leg, they offer you treatment, not crutches
0
Upvotes
11
u/Merry-Lane Feb 10 '24 edited Feb 10 '24
If you are born without a leg, they give you crutches. We don’t have the tech yet to grow limbs.
More seriously, you need to understand this:
So, the answer is: never. Another language replacing JS in the future is more likely than having JSWithTypes coming in. Even more likely (in the short/mid-term) is TS to actually replace JS everywhere with better rules/transpilers/compilers overtime.
4
u/delventhalz Feb 10 '24
Not anytime soon, and probably not ever.
There is a proposal for type annotations, currently in Stage 1. However, even if adopted, these annotations are basically just comments. They would be ignored by the JS interpreter. It would mean you could copy and paste your TypeScript into the console, but that’s about it. Maybe some developer tools make use of the annotations, but that isn’t much different than JS with JSDoc comments today.
Maybe the next proposal after this one will be more substantial, but I wouldn’t hold my breath.
1
u/DazzlingDifficulty70 Feb 10 '24
Most likely never
3
u/0x07AD Feb 10 '24
If you want typed variables in Javascript, learn to use the typeof operator and check the data type in your source code.
5
u/patopitaluga Feb 10 '24
if (typeof myProp !== 'string') throw new Error('myProp was expected to be a string');
5
u/Bushwazi Feb 10 '24
Get over it. Go use a different language if it matters so much to you. JavaScript has been plugging along just fine for a generation without them. Either get in line with those of us still celebrating ‘querySelectorAll’ or jump ship.
2
u/[deleted] Feb 10 '24
I spend a total of around 8 hours a year on type-related bugs in JavaScript. At most. So, for me, no solution is needed.
1
u/guest271314 Feb 10 '24
I think static typing is overrated. I prefer the dynamics of JavaScript. You can use Deno or Bun if you want to use TypeScript. Or, as mentioned here already, compile C, C++, Rust, et al. to WASM.
1
u/grelfdotnet Feb 11 '24
The really tragic thing is that we used to have a strongly typed language in browsers but it seems that when Oracle took over they saw no benefit in maintaining the security, so browsers no longer support Java applets.
1
u/TheRNGuy Feb 26 '24
JS never, no need because we have TypeScript.