Skip to content

casting with Union types #254

Closed
Closed
@bakesteve

Description

@bakesteve

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);
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions