TypeScript function arrow expression returning object
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 }
}
}
You can add parens:
() => ({x:1,y:2})
This makes the parser understand that the { is not the beginning of a code block.