我有一个代码(不考虑moment
,我添加了流程的存根)
/* @flow */
const moment = (a?: any) => a
const badDateRegex = /(\d|\d\d)\/(\d|\d\d)\/\d{4}/
const makeDatePretty = (date: string) => {
if (badDateRegex.test(date)) {
const [m, d, y] = date.split('/')
return `${y}-${m}-${d}`
}
return date
}
const format = 'MM/YYYY'
const convertDateToMY = (date: Object | string) => moment.isMoment(date)
? typeof date.format === 'function' && date.format(format)
: typeof date === 'string'
? moment(makeDatePretty(date))
: date != null
? moment(date)
: moment()
const convertDatesToMY = (dates: string[] | string | Object[], separator: string = ' - ') =>
Array.isArray(dates)
? dates.map(convertDateToMY).join(separator)
: convertDatesToMY(dates)
流量抛出错误
22: const convertDatesToMY = (dates: string[] | string | Object[], separator: string = ' - ') =>
^ string. This type is incompatible with
22: const convertDatesToMY = (dates: string[] | string | Object[], separator: string = ' - ') =>
^ object type
22: const convertDatesToMY = (dates: string[] | string | Object[], separator: string = ' - ') =>
^ object type. This type is incompatible with
22: const convertDatesToMY = (dates: string[] | string | Object[], separator: string = ' - ') =>
^ string
我在类型声明中遗漏了什么?