how to extend jest expect's extendExport typescript namespace with a custom matcher

Viewed 116

I am using jest's expect package without jest and I was hoping to create a custom matcher that uses declaration merging to add the new matcher but typescript does not pick up the merged type.

I'm not using jest so extending the global jest namespace will not work here.

The exported type from expect looks like this:

import { Matchers as MatcherInterface, MatcherState as JestMatcherState, Expect } from './types';
declare const expectExport: Expect;
declare namespace expectExport {
    type MatcherState = JestMatcherState;
    interface Matchers<R> extends MatcherInterface<R> {
    }
}
export = expectExport;

I want to use declaration merging to add a new matcher to the Matches<R> interface.

I tried creating an index.d.ts file in the root and adding this:

export {};

declare namespace extendExport {
  interface Matchers<R> {
    toWorkProperly(a: number): R;
  }
}

But the type is not picked up by typescript.

0 Answers
Related