Skip to content

Commit

Permalink
refactor(jest-cli): rework internal typings (#13405)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Oct 8, 2022
1 parent 9984ba1 commit f9439d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
16 changes: 3 additions & 13 deletions packages/jest-cli/src/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {MalformedPackageJsonError, NotFoundPackageJsonError} from './errors';
import generateConfigFile from './generateConfigFile';
import modifyPackageJson from './modifyPackageJson';
import defaultQuestions, {testScriptQuestion} from './questions';
import type {ProjectPackageJson} from './types';
import type {ProjectPackageJson, PromptsResults} from './types';

const {
JEST_CONFIG_BASE_NAME,
Expand All @@ -26,15 +26,6 @@ const {
PACKAGE_JSON,
} = constants;

type PromptsResults = {
useTypescript: boolean;
clearMocks: boolean;
coverage: boolean;
coverageProvider: boolean;
environment: boolean;
scripts: boolean;
};

const getConfigFilename = (ext: string) => JEST_CONFIG_BASE_NAME + ext;

export default async function init(
Expand Down Expand Up @@ -101,12 +92,11 @@ export default async function init(

let promptAborted = false;

// @ts-expect-error: Return type cannot be object - faulty typings
const results: PromptsResults = await prompts(questions, {
const results = (await prompts(questions, {
onCancel: () => {
promptAborted = true;
},
});
})) as PromptsResults;

if (promptAborted) {
console.log();
Expand Down
9 changes: 9 additions & 0 deletions packages/jest-cli/src/init/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ export type ProjectPackageJson = {
scripts?: Record<string, string>;
type?: 'commonjs' | 'module';
};

export type PromptsResults = {
useTypescript: boolean;
clearMocks: boolean;
coverage: boolean;
coverageProvider: boolean;
environment: boolean;
scripts: boolean;
};

0 comments on commit f9439d8

Please sign in to comment.