Enriched Descriptors, maybe ES7 ?

Andrea Giammarchi andrea.giammarchi at gmail.com
Sat Mar 8 10:45:14 PST 2014

Yesterday, after my DHTMLConf talk, some developer asked me to
present/propose my idea about introducing **optional** types in an ES5
compatible way.

Here a quick overview of properties which aim is to guard types or methods
signatures, compatible with overloads for both number of arguments, and
acepted type per each argument and each "guarding group".

propertyName: {
    // ES5
    writable: true/false
    enumerable: true/false
    configurable: true/false
    get: Function
    set: Function
    value: any

    // my complementary, non obtrusive, info
    type: string(as typeof obj)|
          Function(as instanceof)|
          Object(as isPrototypeOf)
    returns: type|[type1, type2, typeN]
    arguments: [type]|[[type], [type]]


The return type can be different too, but I didn't forget to include the
special type 'any' as white flag.

All types and what they mean are [better described here](

The most handy use case is probably
`Object.defineProperties(Class.prototype, typedDescriptrs)` since each
instance will be automatically guarded inheriting the guarded behavior.

As mentioned in [this project goals](
an ideal/dream goal would be having tools capable of
documenting/understanding typed properties such IDE or even "transpilers"
and in a parallel universe JS engines capable to natively use such info per
each descriptor when available and both speed up properties get/set
operations guarding natively the specific type.

As example, this system made possible to implement a [StructType shim](
in few lines of code.

I don't expect this to be discussed soon but I wanted to point at this
library now that is just officially born, despite I've proposed something
similar in my blog already in 2010, so that if there's any big
gotcha/mistake/nonsense in it I am in time to fix/improve or change.

Thanks for your patience reading till the end and for any thoughts or hints
that might come out.

Best Regards and happy JS Fest!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140308/062f869b/attachment.html>

More information about the es-discuss mailing list