This question is similar to Can you limit the scope of a TypeScript global type? but it presents a slightly different scenario that requires clarification (although an answer to this would be greatly appreciated as well).
In my Jest setup, I am attempting to achieve the following:
declare global {
namespace jest {
interface Matchers<R> {
toBeAwesome(this: Matchers<void, HTMLElement>): R;
}
}
}
export {};
expect.extend({
toBeAwesome() {
// Implementation here...
}
});
The issue I'm encountering is that I only want to call the `extend` method in a specific file, meaning I don't want other test files to have access to it. The `declare global {}` block seems to be causing challenges in this context.
I've also experimented with a workaround approach:
declare const expect: jest.Expect & {
<T = any>(actual: T): jest.JestMatchers<T> & {
toBeSelected(this: jest.Matchers<void, HTMLElement>): void;
};
};
Unfortunately, this alternative method isn't yielding the expected results.
An additional attempt involved directly declaring `namespace jest` outside of the global scope, but due to `jest` being a global namespace, a new namespace was created instead of enhancing the existing one.
Is there a way to confine an augmentation to a specific file and its imports within Jest?