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
error TS2345: Argument of type 'ErrorConstructor' is not assignable to parameter of type 'string | RegExp | Error | Constructable | undefined'.
Type 'ErrorConstructor' is not assignable to type 'Constructable'.
Types of parameters 'message' and 'args' are incompatible.
Type 'unknown' is not assignable to type 'string | undefined'.
Type 'unknown' is not assignable to type 'string'.
However, if I remove the first line which makes the test using jest globals, everything works fine.
I found that source definition of expect is different between two tests.
With explicit imports, the definition is coming from node_modules\expect\build\types.d.ts, while with implicit imports, the definition is coming from node_modules\@types\jest\index.d.ts.
Then try to compile it with --strict --esModuleInterop (the latter option is needed to allow the use of import):
$ ./node_modules/.bin/tsc --strict --esModuleInterop test.ts
test.ts:7:22 - error TS2345: Argument of type 'ErrorConstructor' is not assignable to parameter of type 'string | RegExp | Error | Constructable | undefined'.
Type 'ErrorConstructor' is not assignable to type 'Constructable'.
Types of parameters 'message' and 'args' are incompatible.
Type 'unknown' is not assignable to type 'string | undefined'.
Type 'unknown' is not assignable to type 'string'.
7 expect(oops).toThrow(Error);
~~~~~
test.ts:7:22
7 expect(oops).toThrow(Error);
~~~~~
Did you mean to use 'new' with this expression?
Found 1 error.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
🐛 Bug Report
Here's the minimum reproducible snippet.
My project is written in Typescript and I'm using
jest
along withts-jest
.After running the test file, an error is shown.
However, if I remove the first line which makes the test using jest globals, everything works fine.
That is,
I found that source definition of
expect
is different between two tests.With explicit imports, the definition is coming from
node_modules\expect\build\types.d.ts
, while with implicit imports, the definition is coming fromnode_modules\@types\jest\index.d.ts
.To Reproduce
Steps to reproduce the behavior:
Expected behavior
No typing errors.
envinfo
The text was updated successfully, but these errors were encountered: