Hacker News new | ask | show | jobs
by olliej 1555 days ago
No they can’t.

The effect of unenforced type annotations is that sites will end up writing code that is incorrect but works.

Any future attempt to enforce the types will break that content, and so cannot reuse the : syntax for type annotations, but browsers will continue to have to support it.

Mode switches are also not the solution: strict mode is responsible for a huge amount of complexity in the ES spec, and many annoying edge cases in JS implementations. The only reason I was ok with strict mode is the removal of |this| coercion, which could only be done via a mode switch. No other changes in strict mode would have warranted the mode switch.

Adding type annotations to JS would not require a mode switch as it is a purely additive feature (as let and for(of) were), but adding the burden of the syntax without actually adding the semantics makes absolutely no sense - it burns the prefer type annotations syntax, it adds complexity to the language, complexity to the engines, and provides no actual improvements to the ergonomics of the language.

1 comments

Browsers won't enforce the types (which seems to be a non-goal) but build systems and package managers could. Debuggers could warn about type errors when you're using them, maybe?

The types aren't for end users.

Why would you add a type system to the language and then not use it?

You just advocated for developers using tool to validate the types, but that already exists in the form of typescript.

Warnings also don’t matter, as live sites don’t report debugger warning to the host servers (and even if they did they’re unlikely to be fixed).

The only reason to add the type syntax to js is if that type system is going to be enforced.

We don’t want another series of wat presentations about the bizarre JS type system, and we don’t want to add things to the language if there isn’t value in doing so.

The types are for end users insofar as they help ensure that the site operates correctly. Them not being enforced means that you also can’t be notified (through window.on error or whatever it is) that your site has a type bug in it.

Any type syntax added to the JS language must be able to pay for itself, and making it so you can paste some subset of typescript into the JS console is nowhere near justification.

Wasn't this approach the one taken by Python? I don't actually know, since I don't really keep up with Python.

If it was though, how well or poor is it working there?