简体   繁体   中英

Flow: Can you declare output as a cast of an input type?

I have some logging functions that return true / false based on whether or not they logged anything, so I can do:

if (log.onError((err: ?Error), 'can not do thing')) {
  return;
}

I'm trying to fix the annotations for log.onError so that it's effectively:

function onError(err: ?Error, msg: string): (err: boolean) {
  // log stuff
  return !!err;
}

The (err: boolean) at the end isn't valid, but it's what I'm trying to do.

You are supposed to just write the return type, like this:

function onError(err: ?Error, msg: string) : boolean {
  // log stuff
  return !!err;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM