Closed mindplay-dk closed 2 years ago
The type-hint for the throws assertion is somehow incorrect.
throws
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:
https://github.com/lorenzofox3/zora/blob/4ba9b40a49ed3f72dbc2e9773ca434834756641d/assert/src/index.d.ts#L18-L24
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.
you are right 👍
The type-hint for the
throws
assertion is somehow incorrect.No matter what argument I pass, it's the same error:
The type declaration definitely looks odd:
https://github.com/lorenzofox3/zora/blob/4ba9b40a49ed3f72dbc2e9773ca434834756641d/assert/src/index.d.ts#L18-L24
It looks like you were trying to write an overloaded function type?
That would probably look more like this:
Also (and I'm not sure if this is significant, but) the first function could more accurately specify a dependent return-type:
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.