testdouble.js icon indicating copy to clipboard operation
testdouble.js copied to clipboard

Consider relaxing `thenReject` to accept types other than `Error`

Open iliocatallo opened this issue 1 year ago • 2 comments

Description

In a TypeScript code base, thenReject() only accepts Errors.

Issue

It would be nice to allow for different types of rejected values – along the lines of this JavaScript example in the official docs.

Thanks, Ilio.

iliocatallo avatar Mar 27 '23 14:03 iliocatallo

Is this about the project's typings file? As a non-TS user, I've sorta let it be a free-for-all for anyone to contribute edits sensibly, so if you want to take a stab at a PR I would welcome it

searls avatar Mar 27 '23 14:03 searls

Hi Justin,

According to their own declaration, in TypeScript Promise.reject accepts a reason of type any. Since thenReject is a short-hand for thenReturn(Promise.reject), I'd be inclined to use the same type. I'll try and submit a PR later.

Thank you, Ilio.

iliocatallo avatar Mar 27 '23 14:03 iliocatallo