Preparing for type guards

Brendan Eich brendan at
Thu Dec 29 10:09:52 PST 2011

Aren't you assuming a certain kind of guards, namely converting rather than throwing? There's no way to future-proof without more agreement on what the default meaning of x :: Number would be, and (AFAIK) we don't have consensus yet.

Anyway, no one is going to start writing imperative mouthfuls such as Object.guard(x, G) all over. That's not wanted. If guards arrive with compatible semantics, then people would have to plow through their code removing all such boilerplate in favor of guard syntax. But that's a best-case scenario.

Also, just on the number point: people don't all write x = Number(x). You'll see x = +x, or an application-specific conversion -- or no conversion at all (which could be a bug, but might not be due to constraints enforced elsewhere).


----- Original Message -----
From: "Axel Rauschmayer" <axel at>
To: "es-discuss" <es-discuss at>
Sent: Thursday, December 29, 2011 5:38:54 AM
Subject: Preparing for type guards

Once we have type guards, I would expect the JavaScript programming style to slightly change. Currently, number-valued arguments are implemented like this:

    function foo(x) {
        x = Number(x);

With guards, you would use:

    function foo(x :: Number) {

It might make sense to standardize simple guard methods now, for example:

    function foo(x) {
        Object.guard(x, Number);
Advantages: Helps tools (to infer types, to generate documentation), can later be refactored to real guards.

Dr. Axel Rauschmayer
axel at


es-discuss mailing list
es-discuss at

More information about the es-discuss mailing list