If lack of explicit typing is the issue, then his rant would apply to most scripting languages and to single out JS seems odd to me...
If lack of explicit typing is the issue, then his rant would apply to most scripting languages and to single out JS seems odd to me...
JS is in a different spot where to benefit from type checking you have to add a build step or reconfigure your build tool, switch files to another extension, add some "type stubs" dependencies, and make significant changes to the codebase to benefit from type checking.
I think if Node and the browsers started allowing type hints in their parsers you'd see much less resistance to TypeScript.
Other scripting languages are probably not popular enough to matter as much as JS does.
It's similar for JS, believe it or not. Type hints via jsdoc can be just as easily configured for type-checking in our IDE of choice.
Python type hints aren't mandatory either, so they're strictly opt-in and nothing stops users from ignoring them.
Can you clarify how you do this? the type annotation TC39 is not approved; but I'm interested in hearing if you have a "userland" approach that works for you?
The most compliant one seems to be using [JSDoc](https://jsdoc.app/). JSDoc is mostly intended for generating documentation. However, the Typescript compiler can validate types (and can even interoperate with Typescript definitions), if you configure it as such.
In scenarios where you HAVE to write raw Javascript but still would like to do some type validation, this is probably the best solution.
It looks a bit like this:
/**
* Fiddle the widget
* @param {WidgetThing} The widget to fiddle
*/
function fiddleWidget(widget) {
This is a type hint that asserts that `widget` is of type `WidgetThing`.JSDoc also works in the middle of a method:
/** @type {Foo} */
const foo = widget.fetchFoo();
This asserts that `foo` is of type `Foo`. This could in theory also be derived from the return value of `widget.fetchFoo()` of course.JSDoc also has arbitrary type definitions:
/**
* @typedef Foo
* @type {object}
* @property {WidgetThing} parent - the parent that created this Foo.
* @property {string} name - the name of this Foo.
*/
I would stick to transpiling Typescript myself, but I've also seen use cases where that's simply not an option.