diff --git a/packages/jest-cli/src/init/index.ts b/packages/jest-cli/src/init/index.ts index bf4460ad8cb6..6dc793d581b9 100644 --- a/packages/jest-cli/src/init/index.ts +++ b/packages/jest-cli/src/init/index.ts @@ -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, @@ -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( @@ -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(); diff --git a/packages/jest-cli/src/init/types.ts b/packages/jest-cli/src/init/types.ts index 14413b8bedc4..58071a46e7f3 100644 --- a/packages/jest-cli/src/init/types.ts +++ b/packages/jest-cli/src/init/types.ts @@ -12,3 +12,12 @@ export type ProjectPackageJson = { scripts?: Record; type?: 'commonjs' | 'module'; }; + +export type PromptsResults = { + useTypescript: boolean; + clearMocks: boolean; + coverage: boolean; + coverageProvider: boolean; + environment: boolean; + scripts: boolean; +};