ES4 draft: Object initializers

Mark S. Miller erights at
Tue Apr 8 14:37:30 PDT 2008

On Tue, Apr 8, 2008 at 12:20 PM, Lars Hansen <lhansen at> wrote:
>  One facility that was introduced in this draft copies the
>  type tags of 'const' and 'var' attributed properties into
>  the type of the object, for "ease of use".  As a consequence,
>  this test is true:

I don't understand how this could work for "var".

>   { const x: "foo" } is { x: string }
>  I am going to remove that facility again because it violates
>  the "explicit is better than implicit" principle.  IMO the
>  programmer should state her intent:
>   { const x: "foo" } : { x: string }

A possible counter-argument is that the type of "foo" is string rather
than *. We don't make the programmer write

    "foo" :string

in order to get the right type.

>  (It's easy to say that when the literals are simple then the
>  types are obvious, but once they involve more complicated
>  expressions I'm guessing the gains are illusory.)

That's not clear to me. The cases that come to mind compose well:

    { const x: { const y: "bar" } }

has type { x: { y: string }}


More information about the Es4-discuss mailing list