Maybe something changed in Jest 30, but the accepted answer is not working for me. I had to do this in my global.d.ts
file.
import 'jest'
declare global {
namespace jest {
interface Expect {
customMatcher(expected: string): CustomMatcherResult
}
}
}