You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used TypeScript's tsc command to check for the presence of errors caused by type definitions in the test code.
What happened (please provide anything you think will help):
Due to a change introduced in #471, the constructor function cannot be specified as the first argument of toThrowWithMessage. If tried, the following error will be thrown:
error TS2345: Argument of type 'TypeErrorConstructor' is not assignable to parameter of type '(...args: unknown[]) => unknown'.
Types of parameters 'message' and 'args' are incompatible.
Type 'unknown' is not assignable to type 'string | undefined'.
3 }).toThrowWithMessage(TypeError, 'hello world');
~~~~~~~~~
error TS2345: Argument of type 'TypeErrorConstructor' is not assignable to parameter of type '(...args: unknown[]) => unknown'.
Types of parameters 'message' and 'args' are incompatible.
Type 'unknown' is not assignable to type 'string | undefined'.
5 expect.toThrowWithMessage(TypeError, 'hello world');
~~~~~~~~~
Do not use (...args: unknown[]) => unknown in the type definition of an argument that can be passed any function.
This type requires that the function passed as an argument must be able to accept arguments of type unknown.
However, arguments of type unknown cannot be passed to error constructor functions, etc.
Use (...args: any[]) => unknown instead.
Or, given the internal process, new (message: string) => unknown seems appropriate.
Note: The truly correct type is new (message: string | RegExp) => unknown. However, when fixed to this type, we cannot specify the constructor function of the Error object. Perhaps this is a bug in .toThrowWithMessage(), but the Error object constructor function in Node.js works even if a RegExp is passed to the message argument, so I don't think there is any hurry to fix it.
The text was updated successfully, but these errors were encountered:
So when will this fix be published in a v3.0.2 for example? All my projects use jest-extended and it's a bit annoying to always exclude it from updating dependencies to prevent running into this compilation error.
Bug
package
version:jest-extended@3.0.1
node
version: 16.16.0 or 14.19.3 (This bug is caused by a TypeScript type definition and has nothing to do with the Node.js version)pnpm
version: 6.33.0Relevant code
What you did:
I used TypeScript's
tsc
command to check for the presence of errors caused by type definitions in the test code.What happened (please provide anything you think will help):
Due to a change introduced in #471, the constructor function cannot be specified as the first argument of toThrowWithMessage. If tried, the following error will be thrown:
TS Playground link
Do not use
(...args: unknown[]) => unknown
in the type definition of an argument that can be passed any function.This type requires that the function passed as an argument must be able to accept arguments of type
unknown
.However, arguments of type
unknown
cannot be passed to error constructor functions, etc.Use
(...args: any[]) => unknown
instead.Or, given the internal process,
new (message: string) => unknown
seems appropriate.Note: The truly correct type is
new (message: string | RegExp) => unknown
. However, when fixed to this type, we cannot specify the constructor function of the Error object. Perhaps this is a bug in.toThrowWithMessage()
, but the Error object constructor function in Node.js works even if a RegExp is passed to themessage
argument, so I don't think there is any hurry to fix it.The text was updated successfully, but these errors were encountered: