TypeScript function arrow expression returning object

typescript

I have such case:

interface MoverShaker {
    getStatus(): { speed: number; frequency: number; };
}

function GetMoverShaker() : MoverShaker {
    return {
        getStatus: () => { speed: 2, frequency: 3 }
    }
}

I am getting such error: The name 'frequency' does not exist in the current scope. Is such construction possible in TypeScript? If I am using such construction then everything is ok:

function GetMoverShaker(): MoverShaker {
    return {
        getStatus: () => {
             return { speed: 2, frequency: 3 }
        }
}

Best Answer

You can add parens:

() => ({x:1,y:2})

This makes the parser understand that the { is not the beginning of a code block.