-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expect.extend: not possible to correctly extend corresponding TypeScript types #11487
Comments
Unfortunately, #10642 was closed by #11211, which only concerns the "using globals" case, not the issue described by #10642. @SimenB I noted possible solutions both in the issue description an in #10642 (comment), but didn't get an answer. It would be appreciated if you could take another look. |
This allows types to be exported as well. Fixes jestjs#11487 Strictly speaking a breaking change, as expect = require('expect') not longer works, but as this is usually used as a global, this shouldn't be much of an issue.
This allows types to be exported as well. Fixes jestjs#11487 Strictly speaking a breaking change, as expect = require('expect') not longer works, but as this is usually used as a global, this shouldn't be much of an issue.
This allows types to be exported as well. Fixes jestjs#11487 Strictly speaking a breaking change, as expect = require('expect') not longer works, but as this is usually used as a global, this shouldn't be much of an issue.
This allows types to be exported as well. Fixes jestjs#11487 Strictly speaking a breaking change, as expect = require('expect') not longer works, but as this is usually used as a global, this shouldn't be much of an issue.
For anyone looking for a workaround, here's a dirty one: // Use module augmentation on the internal 'expect/build/types'
declare module 'expect/build/types' {
interface Matchers<R> {
// ...
}
} |
This will be supported in Jest 28 (currently available as |
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. |
🐛 Bug Report
When extending expect
it should be possible to extend the corresponding types:
instead you get

To Reproduce
see above
Expected behavior
There should be no error and proper typechecking.
The reason for the issue, is that expect doesn't actually export the
Matchers
interface whichexpect()
returns, but rather a sub-interface. See https://github.com/facebook/jest/blob/master/packages/expect/src/index.ts#L429 .Unfortunately, it isn't possible to do the right thing directly here, i.e., you can't re-export an interface in a namespace. The quick option would be to move the Matchers declaration directly into the namespace instead of importing it from './types'. The proper solution would probably be to use a proper ES export for expect.
Link to repl or repo (highly encouraged)
repl.it link clicky clicky
envinfo
The text was updated successfully, but these errors were encountered: