Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

casting with Union types #254

Closed
bakesteve opened this issue Feb 9, 2015 · 2 comments
Closed

casting with Union types #254

bakesteve opened this issue Feb 9, 2015 · 2 comments

Comments

@bakesteve
Copy link

trying to figure the right way to get flow to recognise this code where I can pass in a Date or a moment

I cant use native js typeofs as far as I can tell.
Know I could just do moment(date).format(...) but while moment is pretty efficient here, feels like there should be a better way to tell flow that isMoment is (basically) a type checking function?

  if(moment.isMoment(date)){
      return date.format(this.props.displayFormat); 
// call of method format Property not found in  [LIB] core.js:166:1,214:1: Date
    }else{
      return moment(date, this.props.inputFormat).format(this.props.displayFormat);
    }
@gabelevi
Copy link
Contributor

Yeah, this is on our minds too. We'd love a way to declare the refinements that a user space function might make to a type. Ideally you'd be able to declare something like

isMoment(x: any): x is moment { ... }

which would tell Flow that if isMoment is true then the argument is a moment.

@gabelevi
Copy link
Contributor

Tracking this issue in #34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants