This project is read-only.

Unexpected compilation of () => { foo:"bar" }

Topics: General, Language Specification
Feb 13, 2014 at 9:19 AM
You'd expect
var f = () => { foo:"bar" }
to compile to
var f = function () {
    return { foo: "bar" };
but actually it compiles to
var f = function () {
I understand why it does that, but I think compiler should at, at least, issue a warning, because this can lead to subtle bugs. Labels are unusual in typescript/javascript, particularly in this simple case.
Feb 13, 2014 at 10:12 AM
Add parenthesis around {foo: "bar"} if you want the object literal to be the return value.

This is consistent with the Ecmascript spec.
Feb 14, 2014 at 4:16 PM
It seems like you would either want a compiler warning in this case, or a lint tool error (and mandatory lint tool usage).
Feb 17, 2014 at 8:49 AM
A compiler warning would be helpful. If there is more than one member in the object literal, it would be nice if the compiler reported a more helpful error message than ';' expected , perhaps something like ';' expected (did you forget the parenthesis?)
Mar 1, 2014 at 5:43 PM
=> is not replacement of return

is it what you want to achieve?

var f = () {return { foo:"bar" }};