Preparing for type guards

Axel Rauschmayer axel at
Thu Dec 29 05:38:54 PST 2011

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


More information about the es-discuss mailing list