typescript - (): meaning in javascript function -


i looking @ piece of code in react application:

export const clickoptoutmessage = (): clickoptoutmessage => ({   type: click_opt_out_message, }); 

what (): do? having trouble googling due fact it's bunch of characters.

i'll try explain step step (sorry if know except ending, people may learn new)

() => { /** function body goes here **/ } 

is arrow function

() => {}  //basically equals: (function () {}).bind(this) 

it have context written.

in typescript can write function return type, this:

function(): number {   return 2; } 

so, know since arrow function function different syntax - (): type return type!

export const clickoptoutmessage = (): clickoptoutmessage => ({   type: click_opt_out_message, }); 

somewhere in code looked at, there piece:

const click_opt_out_message = "click_opt_out_message"; // value can differ in code observed  type clickoptoutmessage = {   type: "click_opt_out_message" } 

as can see,

(): clickoptoutmessage 

pretty tells type of return value.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -