what does the colon mean in Javascript after funct

2020-04-10 04:34发布

I saw the Facebook F8 app code there is a ":" after the function

function setup(): React.Component {
  ...
}

what does this mean?

inheritance?

2条回答
SAY GOODBYE
2楼-- · 2020-04-10 04:39

Usually it's flowtype annotation and in this case means that setup() returns a React.Component. Or it could be TypeScript as well, can't make sophisticated guess in this particular case.

查看更多
ら.Afraid
3楼-- · 2020-04-10 05:03

I think that is the return type of the function setup(), if you analyze different examples you will see that syntax in method parameters too

function user(state: State = initialState, action: Action): State {
  // some code
  return state;
}

edit: is flow, a static type checker from facebook: https://flow.org/

查看更多
登录 后发表回答