This is the last piece of work that's come out of the discussion in #1794.
The t.throws() and t.throwsAsync() assertions are currently typed to return any and Promise<any> respectively. This is because they only return an error if one was actually thrown. If the assertion fails they return undefined and execution continues.
Whilst theoretically correct, we don't feel it's the pragmatic choice. Instead we should type these assertions to return Error / Promise<Error>. Additionally it'd be great if the assertions could be typed as generics so you can provide your own Error subclass (const err = t.throws<MyError>(fn) or const err: MyError = t.throws(fn)). Note that the assertion requires that an Error instance is thrown, so the generic shouldn't take any value.
This should come with some example code in test/flow-types and test/ts-types, and be documented in our Flow and TypeScript recipes.
We can land implementations for Flow and TypeScript separately, though keep in mind that we like to keep diffs between the index.d.ts and index.js.flow files to a minimum.
This is the last piece of work that's come out of the discussion in #1794.
The
t.throws()andt.throwsAsync()assertions are currently typed to returnanyandPromise<any>respectively. This is because they only return an error if one was actually thrown. If the assertion fails they returnundefinedand execution continues.Whilst theoretically correct, we don't feel it's the pragmatic choice. Instead we should type these assertions to return
Error/Promise<Error>. Additionally it'd be great if the assertions could be typed as generics so you can provide your ownErrorsubclass (const err = t.throws<MyError>(fn)orconst err: MyError = t.throws(fn)). Note that the assertion requires that anErrorinstance is thrown, so the generic shouldn't take any value.This should come with some example code in
test/flow-typesandtest/ts-types, and be documented in our Flow and TypeScript recipes.We can land implementations for Flow and TypeScript separately, though keep in mind that we like to keep diffs between the
index.d.tsandindex.js.flowfiles to a minimum.