Seems to happen on any version I've tried so far:
type DateCallback = (value: Date) => Promise<any>
function foo(value: number): Promise<any> {
return Promise.resolve()
}
(foo: DateCallback);
7: (foo: DateCallback);
^ function. This type is incompatible with
7: (foo: DateCallback);
^ function type
This parameter is incompatible:
1: type DateCallback = (value: Date) => Promise<any>
^ Date. This type is incompatible with
3: function foo(value: number): Promise<any> {
^ number
No errors!
Reduced case:
declare var x: Date;
(x: number); // no error
whoa!
It must have to do with making Flow support comparisons between numbers and Dates
This a major was a major "WAT" moment for me? Is this intentional? One would expect this to throw an error:
const time: number = new Date();
@jedwards1211 looks like you are correct. Removing instances of Date from the numeric test at https://github.com/facebook/flow/blob/master/src/typing/flow_js.ml#L7312-L7313 fixes this particular issue, but makes it impossible to perform numeric operations on Dates
One solution might be to remove the numeric attribute of Date and force users to do Number(myDate) > Number(theirDate).
Agreed. Date and number share some common arithmetic operations but they're definitely not the same type.
I think it's possible to fix this issue without breaking support for number + Date and so forth. Explicit casting doesn't have to be necessary.
Funny you should mention number + Date! Turns out + stringifies Date, and all the other numeric operators numberifies Date.

Meanwhile flow happily accepts const a: number = new Date() + 12;
Most helpful comment
@jedwards1211 looks like you are correct. Removing instances of Date from the numeric test at https://github.com/facebook/flow/blob/master/src/typing/flow_js.ml#L7312-L7313 fixes this particular issue, but makes it impossible to perform numeric operations on Dates