Skip to content

Commit

Permalink
interface over type so we can extend
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 17, 2019
1 parent 6809772 commit 31718fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions packages/babel-jest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ const THIS_FILE = fs.readFileSync(__filename);
const jestPresetPath = require.resolve('babel-preset-jest');
const babelIstanbulPlugin = require.resolve('babel-plugin-istanbul');

// Make it non-optional
type TransformerWithFactory = Transformer & {
createTransformer: (options?: TransformOptions) => TransformerWithFactory;
};
// Narrow down the types
interface BabelJestTransformer extends Transformer {
canInstrument: true;
createTransformer: (options?: TransformOptions) => BabelJestTransformer;
}

const createTransformer = (
options: TransformOptions = {},
): TransformerWithFactory => {
): BabelJestTransformer => {
options = {
...options,
// @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/33118
Expand Down Expand Up @@ -64,7 +65,7 @@ const createTransformer = (
return babelConfig;
}

const transformer: TransformerWithFactory = {
const transformer: BabelJestTransformer = {
canInstrument: true,
createTransformer,
getCacheKey(
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-transform/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type CacheKeyOptions = {
rootDir: string;
};

export type Transformer = {
export interface Transformer {
canInstrument?: boolean;
createTransformer?: (options?: any) => Transformer;

Expand All @@ -68,4 +68,4 @@ export type Transformer = {
config: Config.ProjectConfig,
options?: TransformOptions,
) => string | TransformedSource;
};
}

0 comments on commit 31718fd

Please sign in to comment.