Bad type-declaration for `throws`
mindplay-dk opened this issue · 1 comments
mindplay-dk commented
The type-hint for the throws
assertion is somehow incorrect.
No matter what argument I pass, it's the same error:
Argument of type 'string' is not assignable to parameter of type '(Function | RegExp) & (string | undefined)'.ts(2345)
The type declaration definitely looks odd:
Lines 18 to 24 in 4ba9b40
It looks like you were trying to write an overloaded function type?
That would probably look more like this:
type ErrorAssertionFunction = {
(fn: Function, expected: RegExp | Function, description?: string | undefined): IAssertionResult<RegExp | Function>;
(fn: Function, description?: string | undefined): IAssertionResult<undefined>;
}
Also (and I'm not sure if this is significant, but) the first function could more accurately specify a dependent return-type:
type ErrorAssertionFunction = {
<TResult extends RegExp | Function>(
fn: Function,
expected: TResult,
description?: string | undefined): IAssertionResult<TResult>;
(fn: Function, description?: string | undefined): IAssertionResult<undefined>;
}
I'm not sure anyone actually uses the return-type for anything? I've never used it myself - but since it is part of the API, the generic form should be more accurate.
lorenzofox3 commented
you are right 👍