This project is read-only.

Lambda type inference and type annotation

Topics: Language Specification
Dec 10, 2012 at 3:40 PM

correct code:

s:()=>{strokeColor:string;} = () => { return { strokeColor: 'blue' } }


f:()=>{strokeColor:string;} = () => {strokeColor: 'blue'}

The compiler doesn't show neither error nor warning in the second case. Is it a bug in the compliler ?


Dec 10, 2012 at 10:49 PM

The ES6 committee has determined that in the ambiguous case of the second example, the { } is to always be interpreted as "method body" rather than "object literal". It's legal syntax here -- a 'goto' label ('strokeColor:') followed by a string literal expression statement ("'blue'").