diff --git a/.eslintrc.js b/.eslintrc.js index b72d563d7295..e326c04673cc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,6 +26,7 @@ module.exports = { 'error', {argsIgnorePattern: '^_'}, ], + '@typescript-eslint/prefer-ts-expect-error': 'error', // Since we do `export =`. Remove for Jest 25 'import/default': 'off', 'import/order': 'error', diff --git a/package.json b/package.json index 2d0915ab87c4..5b759bf35f89 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "strip-ansi": "^6.0.0", "tempy": "^0.5.0", "throat": "^5.0.0", - "typescript": "^3.8.2", + "typescript": "^3.9.2", "which": "^2.0.1" }, "scripts": { diff --git a/packages/babel-plugin-jest-hoist/src/index.ts b/packages/babel-plugin-jest-hoist/src/index.ts index 714154256109..a9cbe1a0f65e 100644 --- a/packages/babel-plugin-jest-hoist/src/index.ts +++ b/packages/babel-plugin-jest-hoist/src/index.ts @@ -113,7 +113,7 @@ FUNCTIONS.mock = args => { const ids: Set> = new Set(); const parentScope = moduleFactory.parentPath.scope; - // @ts-ignore: ReferencedIdentifier is not known on visitors + // @ts-expect-error: ReferencedIdentifier is not known on visitors moduleFactory.traverse(IDVisitor, {ids}); for (const id of ids) { const {name} = id.node; diff --git a/packages/jest-circus/src/__tests__/circusItTestError.test.ts b/packages/jest-circus/src/__tests__/circusItTestError.test.ts index 56e7b8fae366..d2dc7e5de6cf 100644 --- a/packages/jest-circus/src/__tests__/circusItTestError.test.ts +++ b/packages/jest-circus/src/__tests__/circusItTestError.test.ts @@ -29,7 +29,7 @@ describe('test/it error throwing', () => { }); it(`it throws error with missing callback function`, () => { expect(() => { - // @ts-ignore: Easy, we're testing runtime errors here + // @ts-expect-error: Easy, we're testing runtime errors here circusIt('test2'); }).toThrowError( 'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.', @@ -37,13 +37,13 @@ describe('test/it error throwing', () => { }); it(`it throws an error when first argument isn't a string`, () => { expect(() => { - // @ts-ignore: Easy, we're testing runtime errors here + // @ts-expect-error: Easy, we're testing runtime errors here circusIt(() => {}); }).toThrowError('Invalid first argument, () => {}. It must be a string.'); }); it('it throws an error when callback function is not a function', () => { expect(() => { - // @ts-ignore: Easy, we're testing runtime errors here + // @ts-expect-error: Easy, we're testing runtime errors here circusIt('test4', 'test4b'); }).toThrowError( 'Invalid second argument, test4b. It must be a callback function.', @@ -56,7 +56,7 @@ describe('test/it error throwing', () => { }); it(`test throws error with missing callback function`, () => { expect(() => { - // @ts-ignore: Easy, we're testing runtime errors here + // @ts-expect-error: Easy, we're testing runtime errors here circusTest('test6'); }).toThrowError( 'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.', @@ -64,13 +64,13 @@ describe('test/it error throwing', () => { }); it(`test throws an error when first argument isn't a string`, () => { expect(() => { - // @ts-ignore: Easy, we're testing runtime errors here + // @ts-expect-error: Easy, we're testing runtime errors here circusTest(() => {}); }).toThrowError('Invalid first argument, () => {}. It must be a string.'); }); it('test throws an error when callback function is not a function', () => { expect(() => { - // @ts-ignore: Easy, we're testing runtime errors here + // @ts-expect-error: Easy, we're testing runtime errors here circusTest('test8', 'test8b'); }).toThrowError( 'Invalid second argument, test8b. It must be a callback function.', diff --git a/packages/jest-circus/src/__tests__/circusItTodoTestError.test.ts b/packages/jest-circus/src/__tests__/circusItTodoTestError.test.ts index 1eb655de77dd..b783b7b3069a 100644 --- a/packages/jest-circus/src/__tests__/circusItTodoTestError.test.ts +++ b/packages/jest-circus/src/__tests__/circusItTodoTestError.test.ts @@ -22,7 +22,7 @@ aliasCircusIt(); describe('test/it.todo error throwing', () => { it('todo throws error when given no arguments', () => { expect(() => { - // @ts-ignore: Testing runtime errors here + // @ts-expect-error: Testing runtime errors here circusIt.todo(); }).toThrowError('Todo must be called with only a description.'); }); @@ -33,7 +33,7 @@ describe('test/it.todo error throwing', () => { }); it('todo throws error when given none string description', () => { expect(() => { - // @ts-ignore: Testing runtime errors here + // @ts-expect-error: Testing runtime errors here circusIt.todo(() => {}); }).toThrowError('Todo must be called with only a description.'); }); diff --git a/packages/jest-cli/src/__tests__/cli/args.test.ts b/packages/jest-cli/src/__tests__/cli/args.test.ts index 46ff7a7e4aed..6a3808f704c0 100644 --- a/packages/jest-cli/src/__tests__/cli/args.test.ts +++ b/packages/jest-cli/src/__tests__/cli/args.test.ts @@ -101,11 +101,11 @@ describe('check', () => { describe('buildArgv', () => { it('should return only camelcased args ', () => { - // @ts-ignore + // @ts-expect-error const mockProcessArgv = jest .spyOn(process.argv, 'slice') .mockImplementation(() => ['--clear-mocks']); - // @ts-ignore + // @ts-expect-error const actual = buildArgv(null); expect(actual).not.toHaveProperty('clear-mocks'); expect(actual).toHaveProperty('clearMocks', true); diff --git a/packages/jest-cli/src/init/index.ts b/packages/jest-cli/src/init/index.ts index bd7c030b09e3..7a92a29ec0d7 100644 --- a/packages/jest-cli/src/init/index.ts +++ b/packages/jest-cli/src/init/index.ts @@ -108,7 +108,7 @@ export default async ( let promptAborted: boolean = false; - // @ts-ignore: Return type cannot be object - faulty typings + // @ts-expect-error: Return type cannot be object - faulty typings const results: PromptsResults = await prompts(questions, { onCancel: () => { promptAborted = true; diff --git a/packages/jest-config/src/__tests__/getMaxWorkers.test.ts b/packages/jest-config/src/__tests__/getMaxWorkers.test.ts index 443db5ec141b..9710ad4e87ae 100644 --- a/packages/jest-config/src/__tests__/getMaxWorkers.test.ts +++ b/packages/jest-config/src/__tests__/getMaxWorkers.test.ts @@ -39,19 +39,19 @@ describe('getMaxWorkers', () => { describe('% based', () => { it('50% = 2 workers', () => { const argv = {maxWorkers: '50%'}; - // @ts-ignore: need to fix the typing + // @ts-expect-error: need to fix the typing expect(getMaxWorkers(argv)).toBe(2); }); it('< 0 workers should become 1', () => { const argv = {maxWorkers: '1%'}; - // @ts-ignore: need to fix the typing + // @ts-expect-error: need to fix the typing expect(getMaxWorkers(argv)).toBe(1); }); it("0% shouldn't break", () => { const argv = {maxWorkers: '0%'}; - // @ts-ignore: need to fix the typing + // @ts-expect-error: need to fix the typing expect(getMaxWorkers(argv)).toBe(1); }); }); diff --git a/packages/jest-config/src/__tests__/readConfig.test.ts b/packages/jest-config/src/__tests__/readConfig.test.ts index 8566c78423e2..1452e8355171 100644 --- a/packages/jest-config/src/__tests__/readConfig.test.ts +++ b/packages/jest-config/src/__tests__/readConfig.test.ts @@ -10,7 +10,7 @@ import {readConfig} from '../index'; test('readConfig() throws when an object is passed without a file path', async () => { await expect( readConfig( - // @ts-ignore + // @ts-expect-error null /* argv */, {} /* packageRootOrConfig */, false /* skipArgvConfigOption */, diff --git a/packages/jest-config/src/__tests__/readConfigs.test.ts b/packages/jest-config/src/__tests__/readConfigs.test.ts index 97fa1b351bf9..25fc0e33c5a8 100644 --- a/packages/jest-config/src/__tests__/readConfigs.test.ts +++ b/packages/jest-config/src/__tests__/readConfigs.test.ts @@ -19,7 +19,7 @@ jest.mock('../readConfigFileAndSetRootDir', () => jest.fn(() => mockResult)); test('readConfigs() throws when called without project paths', async () => { await expect( - // @ts-ignore + // @ts-expect-error readConfigs(null /* argv */, [] /* projectPaths */), ).rejects.toThrowError('jest: No configuration found for any project.'); }); @@ -29,7 +29,7 @@ test('readConfigs() loads async config file', async () => { rootDir: './', })); await expect( - // @ts-ignore + // @ts-expect-error readConfigs( {} /* argv */, ['./some-jest-config-file.js'] /* projectPaths */, @@ -43,7 +43,7 @@ test('readConfigs() reject if async was rejected', async () => { throw new Error('Some error'); }); await expect( - // @ts-ignore + // @ts-expect-error readConfigs( {} /* argv */, ['./some-jest-config-file.js'] /* projectPaths */, diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 8ec7da7f35a2..9f6f35062759 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -140,7 +140,7 @@ const setupPreset = ( } } catch (e) {} - // @ts-ignore: `presetModule` can be null? + // @ts-expect-error: `presetModule` can be null? preset = require(presetModule); } catch (error) { if (error instanceof SyntaxError || error instanceof TypeError) { @@ -943,7 +943,7 @@ export default function normalize( }); break; } - // @ts-ignore: automock is missing in GlobalConfig, so what + // @ts-expect-error: automock is missing in GlobalConfig, so what newOptions[key] = value; return newOptions; }, newOptions); diff --git a/packages/jest-config/src/readConfigFileAndSetRootDir.ts b/packages/jest-config/src/readConfigFileAndSetRootDir.ts index 0a4628092eb0..06cbaecc10d6 100644 --- a/packages/jest-config/src/readConfigFileAndSetRootDir.ts +++ b/packages/jest-config/src/readConfigFileAndSetRootDir.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import {pathToFileURL} from 'url'; import * as fs from 'graceful-fs'; import type {Config} from '@jest/types'; -// @ts-ignore: vendored +// @ts-expect-error: vendored import jsonlint from './vendor/jsonlint'; import {JEST_CONFIG_EXT_JSON, PACKAGE_JSON} from './constants'; diff --git a/packages/jest-core/src/watch.ts b/packages/jest-core/src/watch.ts index b1f60c3878b4..77fb88417783 100644 --- a/packages/jest-core/src/watch.ts +++ b/packages/jest-core/src/watch.ts @@ -504,7 +504,7 @@ const getPluginIdentifier = (plugin: WatchPlugin) => // WatchPlugin is an interface, and it is my understanding interface // static fields are not definable anymore, no idea how to circumvent // this :-( - // @ts-ignore: leave `displayName` be. + // @ts-expect-error: leave `displayName` be. plugin.constructor.displayName || plugin.constructor.name; const getPluginKey = ( diff --git a/packages/jest-environment-jsdom/src/__mocks__/index.ts b/packages/jest-environment-jsdom/src/__mocks__/index.ts index c87188636ec8..6f2641dfb719 100644 --- a/packages/jest-environment-jsdom/src/__mocks__/index.ts +++ b/packages/jest-environment-jsdom/src/__mocks__/index.ts @@ -11,7 +11,7 @@ const vm = jest.requireActual('vm'); const JSDOMEnvironment = jest.createMockFromModule('../index') as jest.Mock; JSDOMEnvironment.mockImplementation(function (config) { - // @ts-ignore + // @ts-expect-error this.global = { JSON, console: {}, @@ -19,7 +19,7 @@ JSDOMEnvironment.mockImplementation(function (config) { const globalValues = {...config.globals}; for (const customGlobalKey in globalValues) { - // @ts-ignore + // @ts-expect-error this.global[customGlobalKey] = globalValues[customGlobalKey]; } }); @@ -28,7 +28,7 @@ JSDOMEnvironment.prototype.runSourceText.mockImplementation(function ( sourceText: string, filename: string, ) { - // @ts-ignore + // @ts-expect-error return vm.runInNewContext(sourceText, this.global, { displayErrors: false, filename, diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index fc30e7e50833..bdd5eec27734 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -38,7 +38,8 @@ class JSDOMEnvironment implements JestEnvironment { virtualConsole: new VirtualConsole().sendTo(options.console || console), ...config.testEnvironmentOptions, }); - const global = (this.global = this.dom.window.document.defaultView as Win); + const global = (this.global = (this.dom.window.document + .defaultView as unknown) as Win); if (!global) { throw new Error('JSDOM did not return a Window object'); @@ -118,7 +119,7 @@ class JSDOMEnvironment implements JestEnvironment { this.global.close(); } this.errorEventListener = null; - // @ts-ignore + // @ts-expect-error this.global = null; this.dom = null; this.fakeTimers = null; diff --git a/packages/jest-environment-node/src/__tests__/node_environment.test.ts b/packages/jest-environment-node/src/__tests__/node_environment.test.ts index 0e760db861e4..3cfb43c6d103 100644 --- a/packages/jest-environment-node/src/__tests__/node_environment.test.ts +++ b/packages/jest-environment-node/src/__tests__/node_environment.test.ts @@ -39,7 +39,7 @@ describe('NodeEnvironment', () => { const timer2 = env1.global.setInterval(() => {}, 0); [timer1, timer2].forEach(timer => { - // @ts-ignore + // @ts-expect-error expect(timer.id).not.toBeUndefined(); expect(typeof timer.ref).toBe('function'); expect(typeof timer.unref).toBe('function'); diff --git a/packages/jest-fake-timers/src/legacyFakeTimers.ts b/packages/jest-fake-timers/src/legacyFakeTimers.ts index f425d4ed1607..6185f77f0c27 100644 --- a/packages/jest-fake-timers/src/legacyFakeTimers.ts +++ b/packages/jest-fake-timers/src/legacyFakeTimers.ts @@ -366,10 +366,11 @@ export default class FakeTimers { private _createMocks() { const fn = (impl: Function) => - // @ts-ignore TODO: figure out better typings here + // @ts-expect-error TODO: figure out better typings here this._moduleMocker.fn().mockImplementation(impl); const promisifiableFakeSetTimeout = fn(this._fakeSetTimeout.bind(this)); + // @ts-expect-error TODO: figure out better typings here promisifiableFakeSetTimeout[util.promisify.custom] = ( delay?: number, arg?: unknown, @@ -382,8 +383,11 @@ export default class FakeTimers { clearInterval: fn(this._fakeClearTimer.bind(this)), clearTimeout: fn(this._fakeClearTimer.bind(this)), nextTick: fn(this._fakeNextTick.bind(this)), + // @ts-expect-error TODO: figure out better typings here setImmediate: fn(this._fakeSetImmediate.bind(this)), + // @ts-expect-error TODO: figure out better typings here setInterval: fn(this._fakeSetInterval.bind(this)), + // @ts-expect-error TODO: figure out better typings here setTimeout: promisifiableFakeSetTimeout, }; } diff --git a/packages/jest-fake-timers/src/modernFakeTimers.ts b/packages/jest-fake-timers/src/modernFakeTimers.ts index b0cd8c479a65..03ca30807a89 100644 --- a/packages/jest-fake-timers/src/modernFakeTimers.ts +++ b/packages/jest-fake-timers/src/modernFakeTimers.ts @@ -81,7 +81,7 @@ export default class FakeTimers { runAllTicks(): void { if (this._checkFakeTimers()) { - // @ts-ignore + // @ts-expect-error this._clock.runMicrotasks(); } } diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index ef1e420400df..572164a4bbf2 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -26,7 +26,7 @@ import HasteModuleMap, { import nodeCrawl = require('./crawlers/node'); import normalizePathSep from './lib/normalizePathSep'; import watchmanCrawl = require('./crawlers/watchman'); -// @ts-ignore: not converted to TypeScript - it's a fork: https://github.com/facebook/jest/pull/5387 +// @ts-expect-error: not converted to TypeScript - it's a fork: https://github.com/facebook/jest/pull/5387 import WatchmanWatcher from './lib/WatchmanWatcher'; import FSEventsWatcher = require('./lib/FSEventsWatcher'); import * as fastPath from './lib/fast_path'; @@ -513,7 +513,6 @@ class HasteMap extends EventEmitter { error.stack = ''; // Remove stack for stack-less errors. } - // @ts-ignore: checking error code is OK if error comes from "fs". if (!['ENOENT', 'EACCES'].includes(error.code)) { throw error; } @@ -677,9 +676,9 @@ class HasteMap extends EventEmitter { private _cleanup() { const worker = this._worker; - // @ts-ignore + // @ts-expect-error if (worker && typeof worker.end === 'function') { - // @ts-ignore + // @ts-expect-error worker.end(); } @@ -701,7 +700,7 @@ class HasteMap extends EventEmitter { if ((options && options.forceInBand) || this._options.maxWorkers <= 1) { this._worker = {getSha1, worker}; } else { - // @ts-ignore: assignment of a worker with custom properties. + // @ts-expect-error: assignment of a worker with custom properties. this._worker = new Worker(require.resolve('./worker'), { exposedMethods: ['getSha1', 'worker'], maxRetries: 3, @@ -789,7 +788,7 @@ class HasteMap extends EventEmitter { let mustCopy = true; const createWatcher = (root: Config.Path): Promise => { - // @ts-ignore: TODO how? "Cannot use 'new' with an expression whose type lacks a call or construct signature." + // @ts-expect-error: TODO how? "Cannot use 'new' with an expression whose type lacks a call or construct signature." const watcher = new Watcher(root, { dot: false, glob: extensions.map(extension => '**/*.' + extension), @@ -1035,7 +1034,7 @@ class HasteMap extends EventEmitter { } end(): Promise { - // @ts-ignore: TODO TS cannot decide if `setInterval` and `clearInterval` comes from NodeJS or the DOM + // @ts-expect-error: TODO TS cannot decide if `setInterval` and `clearInterval` comes from NodeJS or the DOM clearInterval(this._changeInterval); if (!this._watchers.length) { return Promise.resolve(); diff --git a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts index 5cac36f02133..2cf05da9655b 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -11,9 +11,10 @@ import {EventEmitter} from 'events'; import * as fs from 'graceful-fs'; import anymatch, {Matcher} from 'anymatch'; import micromatch = require('micromatch'); -// @ts-ignore no types +// @ts-expect-error no types import walker from 'walker'; +// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error // @ts-ignore: this is for CI which runs linux and might not have this let fsevents: typeof import('fsevents') | null = null; try { diff --git a/packages/jest-jasmine2/src/__tests__/Suite.test.ts b/packages/jest-jasmine2/src/__tests__/Suite.test.ts index e8323ea2e589..caf44ac93ffa 100644 --- a/packages/jest-jasmine2/src/__tests__/Suite.test.ts +++ b/packages/jest-jasmine2/src/__tests__/Suite.test.ts @@ -19,7 +19,7 @@ describe('Suite', () => { it("doesn't throw on addExpectationResult when there are no children", () => { expect(() => { - // @ts-ignore + // @ts-expect-error suite.addExpectationResult(); }).not.toThrow(); }); diff --git a/packages/jest-jasmine2/src/__tests__/itTestError.test.ts b/packages/jest-jasmine2/src/__tests__/itTestError.test.ts index e230949e8f28..2c37efeab2c8 100644 --- a/packages/jest-jasmine2/src/__tests__/itTestError.test.ts +++ b/packages/jest-jasmine2/src/__tests__/itTestError.test.ts @@ -16,13 +16,13 @@ describe('test/it error throwing', () => { }); it(`it throws an error when first argument isn't a string`, () => { expect(() => { - // @ts-ignore + // @ts-expect-error it(() => {}); }).toThrowError(`Invalid first argument, () => {}. It must be a string.`); }); it('it throws an error when callback function is not a function', () => { expect(() => { - // @ts-ignore + // @ts-expect-error it('test3', 'test3b'); }).toThrowError( 'Invalid second argument, test3b. It must be a callback function.', @@ -37,13 +37,13 @@ describe('test/it error throwing', () => { }); test(`test throws an error when first argument isn't a string`, () => { expect(() => { - // @ts-ignore + // @ts-expect-error test(() => {}); }).toThrowError(`Invalid first argument, () => {}. It must be a string.`); }); test('test throws an error when callback function is not a function', () => { expect(() => { - // @ts-ignore + // @ts-expect-error test('test6', 'test6b'); }).toThrowError( 'Invalid second argument, test6b. It must be a callback function.', diff --git a/packages/jest-jasmine2/src/__tests__/queueRunner.test.ts b/packages/jest-jasmine2/src/__tests__/queueRunner.test.ts index 325c41042e0e..9cbf1570dac4 100644 --- a/packages/jest-jasmine2/src/__tests__/queueRunner.test.ts +++ b/packages/jest-jasmine2/src/__tests__/queueRunner.test.ts @@ -26,7 +26,7 @@ describe('queueRunner', () => { ], setTimeout, }; - // @ts-ignore + // @ts-expect-error await queueRunner(options); expect(fnOne).toHaveBeenCalled(); expect(fnTwo).toHaveBeenCalled(); @@ -50,7 +50,7 @@ describe('queueRunner', () => { ], setTimeout, }; - // @ts-ignore + // @ts-expect-error await queueRunner(options); expect(fnOne).toHaveBeenCalled(); expect(fail).toHaveBeenCalled(); @@ -79,7 +79,7 @@ describe('queueRunner', () => { ], setTimeout, }; - // @ts-ignore + // @ts-expect-error await queueRunner(options); expect(fnOne).toHaveBeenCalled(); expect(onException).toHaveBeenCalledWith(error); @@ -107,7 +107,7 @@ describe('queueRunner', () => { ], setTimeout, }; - // @ts-ignore + // @ts-expect-error await queueRunner(options); expect(fnOne).toHaveBeenCalled(); expect(onException).toHaveBeenCalled(); @@ -127,7 +127,7 @@ describe('queueRunner', () => { queueableFns: [{fn: failFn}], setTimeout, }; - // @ts-ignore + // @ts-expect-error await queueRunner(options); expect(options.fail).toHaveBeenCalledWith('miserably', 'failed'); @@ -152,7 +152,7 @@ describe('queueRunner', () => { ], setTimeout, }; - // @ts-ignore + // @ts-expect-error await queueRunner(options); expect(fnOne).toHaveBeenCalled(); expect(fail).toHaveBeenCalledWith(error); diff --git a/packages/jest-jasmine2/src/__tests__/reporter.test.ts b/packages/jest-jasmine2/src/__tests__/reporter.test.ts index 4e92f9b9cf4a..4bd50777fcc1 100644 --- a/packages/jest-jasmine2/src/__tests__/reporter.test.ts +++ b/packages/jest-jasmine2/src/__tests__/reporter.test.ts @@ -14,7 +14,7 @@ describe('Jasmine2Reporter', () => { let reporter: JasmineReporter; beforeEach(() => { - // @ts-ignore + // @ts-expect-error reporter = new JasmineReporter({}); }); @@ -28,11 +28,11 @@ describe('Jasmine2Reporter', () => { reporter.suiteStarted({description: 'parent'} as SuiteResult); reporter.suiteStarted({description: 'child'} as SuiteResult); reporter.specDone(makeSpec('spec 1')); - // @ts-ignore + // @ts-expect-error reporter.suiteDone(); reporter.suiteStarted({description: 'child 2'} as SuiteResult); reporter.specDone(makeSpec('spec 2')); - // @ts-ignore + // @ts-expect-error reporter.jasmineDone(); return reporter.getResults().then(runResults => { diff --git a/packages/jest-jasmine2/src/__tests__/todoError.test.ts b/packages/jest-jasmine2/src/__tests__/todoError.test.ts index 758cfda9140e..aab30f522aca 100644 --- a/packages/jest-jasmine2/src/__tests__/todoError.test.ts +++ b/packages/jest-jasmine2/src/__tests__/todoError.test.ts @@ -9,7 +9,7 @@ describe('test/it.todo error throwing', () => { it('it throws error when given no arguments', () => { expect(() => { - // @ts-ignore + // @ts-expect-error it.todo(); }).toThrowError('Todo must be called with only a description.'); }); @@ -20,7 +20,7 @@ describe('test/it.todo error throwing', () => { }); it('it throws error when given none string description', () => { expect(() => { - // @ts-ignore + // @ts-expect-error it.todo(() => {}); }).toThrowError('Todo must be called with only a description.'); }); diff --git a/packages/jest-jasmine2/src/errorOnPrivate.ts b/packages/jest-jasmine2/src/errorOnPrivate.ts index b619dba153f9..0df3568af49a 100644 --- a/packages/jest-jasmine2/src/errorOnPrivate.ts +++ b/packages/jest-jasmine2/src/errorOnPrivate.ts @@ -53,7 +53,7 @@ export function installErrorOnPrivate(global: Global.Global): void { (Object.keys(disabledJasmineMethods) as Array< DisabledJasmineMethodsKeys >).forEach(methodName => { - // @ts-ignore + // @ts-expect-error jasmine[methodName] = () => { throwAtFunction(disabledJasmineMethods[methodName], jasmine[methodName]); }; diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index 8d77212ba5ba..7c081b7846b1 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -52,7 +52,7 @@ async function jasmine2( const stack = getCallsite(1, runtime.getSourceMaps()); const it = originalIt(...args); - // @ts-ignore + // @ts-expect-error it.result.__callsite = stack; return it; @@ -63,7 +63,7 @@ async function jasmine2( const stack = getCallsite(1, runtime.getSourceMaps()); const xit = originalXit(...args); - // @ts-ignore + // @ts-expect-error xit.result.__callsite = stack; return xit; @@ -74,7 +74,7 @@ async function jasmine2( const stack = getCallsite(1, runtime.getSourceMaps()); const fit = originalFit(...args); - // @ts-ignore + // @ts-expect-error fit.result.__callsite = stack; return fit; diff --git a/packages/jest-jasmine2/src/jasmine/Env.ts b/packages/jest-jasmine2/src/jasmine/Env.ts index a94173a7321f..cc2acc3eee6a 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.ts +++ b/packages/jest-jasmine2/src/jasmine/Env.ts @@ -384,7 +384,7 @@ export default function (j$: Jasmine) { suite.pend(); } if (currentDeclarationSuite.markedTodo) { - // @ts-ignore TODO Possible error: Suite does not have todo method + // @ts-expect-error TODO Possible error: Suite does not have todo method suite.todo(); } addSpecsToSuite(suite, specDefinitions); @@ -664,7 +664,7 @@ export default function (j$: Jasmine) { (error && error.name === AssertionError.name) ) { checkIsError = false; - // @ts-ignore TODO Possible error: j$.Spec does not have expand property + // @ts-expect-error TODO Possible error: j$.Spec does not have expand property message = assertionErrorMessage(error, {expand: j$.Spec.expand}); } else { const check = isError(error); diff --git a/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts b/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts index a4548b69b212..7995d25424d5 100644 --- a/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts +++ b/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts @@ -37,17 +37,17 @@ export default class ReportDispatcher implements Reporter { provideFallbackReporter: (reporter: Reporter) => void; clearReporters: () => void; - // @ts-ignore + // @ts-expect-error jasmineDone: (runDetails: RunDetails) => void; - // @ts-ignore + // @ts-expect-error jasmineStarted: (runDetails: RunDetails) => void; - // @ts-ignore + // @ts-expect-error specDone: (result: SpecResult) => void; - // @ts-ignore + // @ts-expect-error specStarted: (spec: SpecResult) => void; - // @ts-ignore + // @ts-expect-error suiteDone: (result: SuiteResult) => void; - // @ts-ignore + // @ts-expect-error suiteStarted: (result: SuiteResult) => void; constructor(methods: Array) { @@ -86,7 +86,7 @@ export default class ReportDispatcher implements Reporter { for (let i = 0; i < reporters.length; i++) { const reporter = reporters[i]; if (reporter[method]) { - // @ts-ignore + // @ts-expect-error reporter[method].apply(reporter, args); } } diff --git a/packages/jest-jasmine2/src/jasmine/Spec.ts b/packages/jest-jasmine2/src/jasmine/Spec.ts index a8d4e53a5685..8f0bcdfe5db4 100644 --- a/packages/jest-jasmine2/src/jasmine/Spec.ts +++ b/packages/jest-jasmine2/src/jasmine/Spec.ts @@ -142,7 +142,7 @@ export default class Spec { this.queueableFn.initError = this.initError; - // @ts-ignore + // @ts-expect-error this.result = { id: this.id, description: this.description, @@ -192,7 +192,7 @@ export default class Spec { this.currentRun = this.queueRunnerFactory({ queueableFns: allFns, onException() { - // @ts-ignore + // @ts-expect-error self.onException.apply(self, arguments); }, userContext: this.userContext(), diff --git a/packages/jest-jasmine2/src/jestExpect.ts b/packages/jest-jasmine2/src/jestExpect.ts index 6d8cf5a9cb63..e0495cb9f0b7 100644 --- a/packages/jest-jasmine2/src/jestExpect.ts +++ b/packages/jest-jasmine2/src/jestExpect.ts @@ -59,12 +59,12 @@ export default (config: {expand: boolean}): void => { return this.isNot ? negativeCompare.apply( null, - // @ts-ignore + // @ts-expect-error args, ) : result.compare.apply( null, - // @ts-ignore + // @ts-expect-error args, ); }; diff --git a/packages/jest-jasmine2/src/queueRunner.ts b/packages/jest-jasmine2/src/queueRunner.ts index c57130a201cb..21af10a51de6 100644 --- a/packages/jest-jasmine2/src/queueRunner.ts +++ b/packages/jest-jasmine2/src/queueRunner.ts @@ -6,7 +6,7 @@ */ import {formatTime} from 'jest-util'; -// @ts-ignore ignore vendor file +// @ts-expect-error ignore vendor file import PCancelable from './PCancelable'; import pTimeout from './pTimeout'; diff --git a/packages/jest-leak-detector/src/__tests__/index.test.ts b/packages/jest-leak-detector/src/__tests__/index.test.ts index 1d8f0c6f0896..e5833ccf3acd 100644 --- a/packages/jest-leak-detector/src/__tests__/index.test.ts +++ b/packages/jest-leak-detector/src/__tests__/index.test.ts @@ -31,7 +31,7 @@ it('complains if the value is a primitive', () => { it('does not show the GC if hidden', async () => { const detector = new LeakDetector({}); - // @ts-ignore: purposefully removed + // @ts-expect-error: purposefully removed global.gc = undefined; await detector.isLeaking(); expect(global.gc).not.toBeDefined(); diff --git a/packages/jest-matcher-utils/src/__tests__/index.test.ts b/packages/jest-matcher-utils/src/__tests__/index.test.ts index 2afa9f79de62..96412e07d461 100644 --- a/packages/jest-matcher-utils/src/__tests__/index.test.ts +++ b/packages/jest-matcher-utils/src/__tests__/index.test.ts @@ -105,12 +105,12 @@ describe('stringify()', () => { describe('ensureNumbers()', () => { test('dont throw error when variables are numbers', () => { expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers(1, 2); }).not.toThrow(); if (isBigIntDefined) { expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers(BigInt(1), BigInt(2)); }).not.toThrow(); } @@ -118,14 +118,14 @@ describe('ensureNumbers()', () => { test('throws error when expected is not a number (backward compatibility)', () => { expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers(1, 'not_a_number', '.toBeCloseTo'); }).toThrowErrorMatchingSnapshot(); }); test('throws error when received is not a number (backward compatibility)', () => { expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers('not_a_number', 3, '.toBeCloseTo'); }).toThrowErrorMatchingSnapshot(); }); @@ -140,7 +140,7 @@ describe('ensureNumbers()', () => { secondArgument: 'precision', }; expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers('', 0, matcherName, options); }).toThrowErrorMatchingSnapshot(); }); @@ -151,7 +151,7 @@ describe('ensureNumbers()', () => { // promise undefined is equivalent to empty string }; expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers(0.1, undefined, matcherName, options); }).toThrowErrorMatchingSnapshot(); }); @@ -162,7 +162,7 @@ describe('ensureNumbers()', () => { promise: 'rejects', }; expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers(0.01, '0', matcherName, options); }).toThrowErrorMatchingSnapshot(); }); @@ -173,7 +173,7 @@ describe('ensureNumbers()', () => { promise: 'rejects', }; expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers(Symbol('0.1'), 0, matcherName, options); }).toThrowErrorMatchingSnapshot(); }); @@ -184,7 +184,7 @@ describe('ensureNumbers()', () => { promise: 'resolves', }; expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers(false, 0, matcherName, options); }).toThrowErrorMatchingSnapshot(); }); @@ -195,7 +195,7 @@ describe('ensureNumbers()', () => { promise: 'resolves', }; expect(() => { - // @ts-ignore + // @ts-expect-error ensureNumbers(0.1, null, matcherName, options); }).toThrowErrorMatchingSnapshot(); }); @@ -205,7 +205,7 @@ describe('ensureNumbers()', () => { describe('ensureNoExpected()', () => { test('dont throw error when undefined', () => { expect(() => { - // @ts-ignore + // @ts-expect-error ensureNoExpected(undefined); }).not.toThrow(); }); diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index a72847029b0d..7251b0a9ec02 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -417,7 +417,6 @@ class ModuleMockerClass { if (!isReadonlyProp(object, prop)) { const propDesc = Object.getOwnPropertyDescriptor(object, prop); - // @ts-ignore Object.__esModule if ((propDesc !== undefined && !propDesc.get) || object.__esModule) { slots.add(prop); } @@ -566,11 +565,11 @@ class ModuleMockerClass { // it easier to interact with mock instance call and // return values if (prototype[slot].type === 'function') { - // @ts-ignore no index signature + // @ts-expect-error no index signature const protoImpl = this[slot]; - // @ts-ignore no index signature + // @ts-expect-error no index signature this[slot] = mocker.generateFromMetadata(prototype[slot]); - // @ts-ignore no index signature + // @ts-expect-error no index signature this[slot]._protoImpl = protoImpl; } }); @@ -795,7 +794,7 @@ class ModuleMockerClass { ): Mock { // metadata not compatible but it's the same type, maybe problem with // overloading of _makeComponent and not _generateMock? - // @ts-ignore + // @ts-expect-error const mock = this._makeComponent(metadata); if (metadata.refID != null) { refs[metadata.refID] = mock; @@ -823,7 +822,7 @@ class ModuleMockerClass { mock.prototype.constructor = mock; } - return mock; + return mock as Mock; } /** @@ -870,11 +869,11 @@ class ModuleMockerClass { metadata.value = component; return metadata; } else if (type === 'function') { - // @ts-ignore this is a function so it has a name + // @ts-expect-error this is a function so it has a name metadata.name = component.name; - // @ts-ignore may be a mock + // @ts-expect-error may be a mock if (component._isMockFunction === true) { - // @ts-ignore may be a mock + // @ts-expect-error may be a mock metadata.mockImpl = component.getMockImplementation(); } } @@ -890,13 +889,13 @@ class ModuleMockerClass { this._getSlots(component).forEach(slot => { if ( type === 'function' && - // @ts-ignore may be a mock + // @ts-expect-error may be a mock component._isMockFunction === true && slot.match(/^mock/) ) { return; } - // @ts-ignore no index signature + // @ts-expect-error no index signature const slotMetadata = this.getMetadata(component[slot], refs); if (slotMetadata) { if (!members) { @@ -978,7 +977,7 @@ class ModuleMockerClass { const isMethodOwner = object.hasOwnProperty(methodName); - // @ts-ignore overriding original method with a Mock + // @ts-expect-error overriding original method with a Mock object[methodName] = this._makeComponent({type: 'function'}, () => { if (isMethodOwner) { object[methodName] = original; @@ -987,7 +986,7 @@ class ModuleMockerClass { } }); - // @ts-ignore original method is now a Mock + // @ts-expect-error original method is now a Mock object[methodName].mockImplementation(function (this: unknown) { return original.apply(this, arguments); }); @@ -1052,9 +1051,9 @@ class ModuleMockerClass { ); } - // @ts-ignore: mock is assignable + // @ts-expect-error: mock is assignable descriptor[accessType] = this._makeComponent({type: 'function'}, () => { - // @ts-ignore: mock is assignable + // @ts-expect-error: mock is assignable descriptor![accessType] = original; Object.defineProperty(obj, propertyName, descriptor!); }); @@ -1062,7 +1061,7 @@ class ModuleMockerClass { (descriptor[accessType] as Mock).mockImplementation(function ( this: unknown, ) { - // @ts-ignore + // @ts-expect-error return original.apply(this, arguments); }); } diff --git a/packages/jest-repl/src/cli/index.ts b/packages/jest-repl/src/cli/index.ts index 94728bc9d1b1..9d027435023c 100644 --- a/packages/jest-repl/src/cli/index.ts +++ b/packages/jest-repl/src/cli/index.ts @@ -21,7 +21,6 @@ const REPL_SCRIPT = require.resolve('./repl.js'); export = function (): void { const argv = yargs.usage(args.usage).options(args.options).argv; - // @ts-ignore: fix this at some point validateCLIOptions(argv, {...args.options, deprecationEntries}); argv._ = [REPL_SCRIPT]; diff --git a/packages/jest-reporters/src/coverage_reporter.ts b/packages/jest-reporters/src/coverage_reporter.ts index 5966bdde9600..7b4ded54abe5 100644 --- a/packages/jest-reporters/src/coverage_reporter.ts +++ b/packages/jest-reporters/src/coverage_reporter.ts @@ -96,10 +96,9 @@ export default class CoverageReporter extends BaseReporter { maxCols: process.stdout.columns || Infinity, ...additionalOptions, }) - // @ts-ignore + // @ts-expect-error .execute(reportContext); }); - // @ts-ignore aggregatedResults.coverageMap = map; } catch (e) { console.error( @@ -111,7 +110,6 @@ export default class CoverageReporter extends BaseReporter { ); } - // @ts-ignore this._checkThreshold(map); } @@ -487,19 +485,13 @@ export default class CoverageReporter extends BaseReporter { } const map = await this._sourceMapStore.transformCoverage(this._coverageMap); - const reportContext = istanbulReport.createContext( - // @ts-ignore - { - // @ts-ignore - coverageMap: map, - dir: this._globalConfig.coverageDirectory, - // @ts-ignore - sourceFinder: this._sourceMapStore.sourceFinder, - watermarks: getWatermarks(this._globalConfig), - }, - ); + const reportContext = istanbulReport.createContext({ + coverageMap: map, + dir: this._globalConfig.coverageDirectory, + sourceFinder: this._sourceMapStore.sourceFinder, + watermarks: getWatermarks(this._globalConfig), + }); - // @ts-ignore return {map, reportContext}; } } diff --git a/packages/jest-reporters/src/notify_reporter.ts b/packages/jest-reporters/src/notify_reporter.ts index 2fda318987d3..f6186f078ca9 100644 --- a/packages/jest-reporters/src/notify_reporter.ts +++ b/packages/jest-reporters/src/notify_reporter.ts @@ -79,7 +79,6 @@ export default class NotifyReporter extends BaseReporter { result.numPassedTests, )} passed`; - // @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42303 this._notifier.notify({icon, message, timeout: false, title}); } else if ( testsHaveRun && @@ -108,7 +107,6 @@ export default class NotifyReporter extends BaseReporter { const quitAnswer = 'Exit tests'; if (!watchMode) { - // @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42303 this._notifier.notify({icon, message, timeout: false, title}); } else { this._notifier.notify( diff --git a/packages/jest-resolve/src/__tests__/resolve.test.ts b/packages/jest-resolve/src/__tests__/resolve.test.ts index 6ecefafd513d..c7d985a0b523 100644 --- a/packages/jest-resolve/src/__tests__/resolve.test.ts +++ b/packages/jest-resolve/src/__tests__/resolve.test.ts @@ -10,7 +10,7 @@ import * as path from 'path'; import * as fs from 'graceful-fs'; import {ModuleMap} from 'jest-haste-map'; import Resolver = require('../'); -// @ts-ignore: js file +// @ts-expect-error: js file import userResolver from '../__mocks__/userResolver'; import nodeModulesPaths from '../nodeModulesPaths'; import defaultResolver from '../defaultResolver'; diff --git a/packages/jest-resolve/src/defaultResolver.ts b/packages/jest-resolve/src/defaultResolver.ts index be1e6cabb1a7..b62270dab5c3 100644 --- a/packages/jest-resolve/src/defaultResolver.ts +++ b/packages/jest-resolve/src/defaultResolver.ts @@ -25,7 +25,7 @@ export default function defaultResolver( path: Config.Path, options: ResolverOptions, ): Config.Path { - // @ts-ignore: the "pnp" version named isn't in DefinitelyTyped + // @ts-expect-error: the "pnp" version named isn't in DefinitelyTyped if (process.versions.pnp) { return pnpResolver(path, options); } diff --git a/packages/jest-resolve/src/index.ts b/packages/jest-resolve/src/index.ts index b678dabbe3dc..42d4bf44afca 100644 --- a/packages/jest-resolve/src/index.ts +++ b/packages/jest-resolve/src/index.ts @@ -192,7 +192,7 @@ class Resolver { }); if (!skipResolution) { - // @ts-ignore: the "pnp" version named isn't in DefinitelyTyped + // @ts-expect-error: the "pnp" version named isn't in DefinitelyTyped module = resolveNodeModule(moduleName, Boolean(process.versions.pnp)); if (module) { diff --git a/packages/jest-resolve/src/isBuiltinModule.ts b/packages/jest-resolve/src/isBuiltinModule.ts index 4df97846acab..63e16aeb59a1 100644 --- a/packages/jest-resolve/src/isBuiltinModule.ts +++ b/packages/jest-resolve/src/isBuiltinModule.ts @@ -7,7 +7,7 @@ import module = require('module'); -// @ts-ignore: "private" api +// "private" api declare const process: { binding(type: string): {}; }; diff --git a/packages/jest-resolve/src/shouldLoadAsEsm.ts b/packages/jest-resolve/src/shouldLoadAsEsm.ts index a1938e70d5e6..cab7b850eae6 100644 --- a/packages/jest-resolve/src/shouldLoadAsEsm.ts +++ b/packages/jest-resolve/src/shouldLoadAsEsm.ts @@ -6,7 +6,7 @@ */ import {dirname, extname} from 'path'; -// @ts-ignore: experimental, not added to the types +// @ts-expect-error: experimental, not added to the types import {SyntheticModule} from 'vm'; import type {Config} from '@jest/types'; import readPkgUp = require('read-pkg-up'); diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index 7abfdf81729c..deb20ff7d7ec 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -38,7 +38,7 @@ function freezeConsole( testConsole: BufferedConsole | CustomConsole | NullConsole, config: Config.ProjectConfig, ) { - // @ts-ignore: `_log` is `private` - we should figure out some proper API here + // @ts-expect-error: `_log` is `private` - we should figure out some proper API here testConsole._log = function fakeConsolePush( _type: LogType, message: LogMessage, diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index aaacea67f06f..47d66dbae539 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -9,12 +9,12 @@ import {URL, fileURLToPath, pathToFileURL} from 'url'; import * as path from 'path'; import { Script, - // @ts-ignore: experimental, not added to the types + // @ts-expect-error: experimental, not added to the types SourceTextModule, - // @ts-ignore: experimental, not added to the types + // @ts-expect-error: experimental, not added to the types SyntheticModule, Context as VMContext, - // @ts-ignore: experimental, not added to the types + // @ts-expect-error: experimental, not added to the types Module as VMModule, compileFunction, } from 'vm'; @@ -450,7 +450,7 @@ class Runtime { const module = new SyntheticModule( ['default'], function () { - // @ts-ignore: TS doesn't know what `this` is + // @ts-expect-error: TS doesn't know what `this` is this.setExport('default', cjs); }, {context, identifier: modulePath}, @@ -686,7 +686,7 @@ class Runtime { requireModuleOrMock(from: Config.Path, moduleName: string): T { // this module is unmockable if (moduleName === '@jest/globals') { - // @ts-ignore: we don't care that it's not assignable to T + // @ts-expect-error: we don't care that it's not assignable to T return this.getGlobalsForCjs(from); } @@ -1112,10 +1112,10 @@ class Runtime { return new SyntheticModule( ['default', ...Object.keys(required)], function () { - // @ts-ignore: TS doesn't know what `this` is + // @ts-expect-error: TS doesn't know what `this` is this.setExport('default', required); Object.entries(required).forEach(([key, value]) => { - // @ts-ignore: TS doesn't know what `this` is + // @ts-expect-error: TS doesn't know what `this` is this.setExport(key, value); }); }, @@ -1141,7 +1141,7 @@ class Runtime { const error = new TypeError( `The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '${filename}'`, ); - // @ts-ignore + // @ts-expect-error error.code = 'ERR_INVALID_ARG_TYPE'; throw error; } @@ -1159,7 +1159,7 @@ class Runtime { class Module extends nativeModule.Module {} Object.entries(nativeModule.Module).forEach(([key, value]) => { - // @ts-ignore + // @ts-expect-error Module[key] = value; }); @@ -1180,7 +1180,7 @@ class Runtime { : '' }`, ); - // @ts-ignore + // @ts-expect-error error.code = 'ERR_INVALID_ARG_TYPE'; throw error; } @@ -1458,14 +1458,14 @@ class Runtime { if (this._environment.global.jasmine) { this._environment.global.jasmine._DEFAULT_TIMEOUT_INTERVAL = timeout; } else { - // @ts-ignore: https://github.com/Microsoft/TypeScript/issues/24587 + // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 this._environment.global[testTimeoutSymbol] = timeout; } return jestObject; }; const retryTimes = (numTestRetries: number) => { - // @ts-ignore: https://github.com/Microsoft/TypeScript/issues/24587 + // @ts-expect-error: https://github.com/Microsoft/TypeScript/issues/24587 this._environment.global[retryTimesSymbol] = numTestRetries; return jestObject; }; @@ -1638,7 +1638,7 @@ class Runtime { Object.keys(globals), function () { Object.entries(globals).forEach(([key, value]) => { - // @ts-ignore: TS doesn't know what `this` is + // @ts-expect-error: TS doesn't know what `this` is this.setExport(key, value); }); }, diff --git a/packages/jest-serializer/src/__tests__/index.test.ts b/packages/jest-serializer/src/__tests__/index.test.ts index 45a6951315a8..174e3de5067c 100644 --- a/packages/jest-serializer/src/__tests__/index.test.ts +++ b/packages/jest-serializer/src/__tests__/index.test.ts @@ -19,7 +19,7 @@ const objs = [ {key1: 'foo', key2: 'bar', key3: {array: [null, {}]}}, {minusInf: -Infinity, nan: NaN, plusInf: +Infinity}, {date: new Date(1234567890), re: /foo/gi}, - // @ts-ignore - testing NaN + // @ts-expect-error - testing NaN { map: new Map([ [NaN, 4], diff --git a/packages/jest-snapshot/src/State.ts b/packages/jest-snapshot/src/State.ts index 8cdfd52b817b..24fbbee262f5 100644 --- a/packages/jest-snapshot/src/State.ts +++ b/packages/jest-snapshot/src/State.ts @@ -54,7 +54,7 @@ type SaveStatus = { export default class SnapshotState { private _counters: Map; private _dirty: boolean; - // @ts-ignore + // @ts-expect-error private _index: number; private _updateSnapshot: Config.SnapshotUpdateState; private _snapshotData: SnapshotData; diff --git a/packages/jest-snapshot/src/__tests__/utils.test.ts b/packages/jest-snapshot/src/__tests__/utils.test.ts index d84e9358866b..4e7816161d23 100644 --- a/packages/jest-snapshot/src/__tests__/utils.test.ts +++ b/packages/jest-snapshot/src/__tests__/utils.test.ts @@ -179,7 +179,7 @@ test('escaping', () => { 'exports[`key`] = `"\'\\\\`;\n', ); - // @ts-ignore + // @ts-expect-error const exports = {}; // eslint-disable-line @typescript-eslint/no-unused-vars // eslint-disable-next-line no-eval const readData = eval('var exports = {}; ' + writtenData + ' exports'); diff --git a/packages/jest-source-map/src/__tests__/getCallsite.test.ts b/packages/jest-source-map/src/__tests__/getCallsite.test.ts index 1eecf64fb65e..7ddf40b4a51b 100644 --- a/packages/jest-source-map/src/__tests__/getCallsite.test.ts +++ b/packages/jest-source-map/src/__tests__/getCallsite.test.ts @@ -44,7 +44,7 @@ describe('getCallsite', () => { const sourceMapColumn = 1; const sourceMapLine = 2; - // @ts-ignore + // @ts-expect-error SourceMap.SourceMapConsumer = class { originalPositionFor(params: Record) { expect(params).toMatchObject({ diff --git a/packages/jest-source-map/src/getCallsite.ts b/packages/jest-source-map/src/getCallsite.ts index ecb903d7729e..863ce4327f94 100644 --- a/packages/jest-source-map/src/getCallsite.ts +++ b/packages/jest-source-map/src/getCallsite.ts @@ -57,7 +57,7 @@ export default ( if (sourceMapFileName) { try { const sourceMap = readFileSync(sourceMapFileName, 'utf8'); - // @ts-ignore: Not allowed to pass string + // @ts-expect-error: Not allowed to pass string addSourceMapConsumer(stack, new SourceMapConsumer(sourceMap)); } catch (e) { // ignore diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index 523d79b34d7c..3b448597d90c 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -20,7 +20,7 @@ describe('formatTestResults', () => { { numFailingTests: 0, perfStats: {end: 2, start: 1}, - // @ts-ignore + // @ts-expect-error testResults: [assertion], }, ], diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index 0cf17915da3c..7e12631195ab 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -16,7 +16,7 @@ import { } from 'jest-util'; import * as fs from 'graceful-fs'; import {transformSync as babelTransform} from '@babel/core'; -// @ts-ignore: should just be `require.resolve`, but the tests mess that up +// @ts-expect-error: should just be `require.resolve`, but the tests mess that up import babelPluginIstanbul from 'babel-plugin-istanbul'; import {fromSource as sourcemapFromSource} from 'convert-source-map'; import HasteMap = require('jest-haste-map'); @@ -563,7 +563,7 @@ export default class ScriptTransformer { /** * @deprecated use `this.shouldTransform` instead */ - // @ts-ignore: Unused and private - remove in Jest 25 + // @ts-expect-error: Unused and private - remove in Jest 25 private _shouldTransform(filename: Config.Path): boolean { return this.shouldTransform(filename); } diff --git a/packages/jest-util/src/__tests__/createProcessObject.test.ts b/packages/jest-util/src/__tests__/createProcessObject.test.ts index c1658f793983..670e4f66b386 100644 --- a/packages/jest-util/src/__tests__/createProcessObject.test.ts +++ b/packages/jest-util/src/__tests__/createProcessObject.test.ts @@ -26,9 +26,9 @@ it('creates a process object that looks like the original one', () => { // "_events" property is checked to ensure event emitter properties are // properly copied. ['argv', 'env', '_events'].forEach(key => { - // @ts-ignore + // @ts-expect-error expect(fakeProcess[key]).toEqual(process[key]); - // @ts-ignore + // @ts-expect-error expect(fakeProcess[key]).not.toBe(process[key]); }); @@ -47,7 +47,7 @@ it('checks that process.env works as expected on Linux platforms', () => { // Existing properties inside process.env are copied to the fake environment. process.env.PROP_STRING = 'foo'; - // @ts-ignore + // @ts-expect-error process.env.PROP_NUMBER = 3; process.env.PROP_UNDEFINED = undefined; diff --git a/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts b/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts index 926bbd540da3..71ac408dec55 100644 --- a/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts +++ b/packages/jest-util/src/__tests__/deepCyclicCopy.test.ts @@ -23,7 +23,7 @@ it('returns the same value for primitive or function values', () => { it('does not execute getters/setters, but copies them', () => { const fn = jest.fn(); const obj = { - // @ts-ignore + // @ts-expect-error get foo() { fn(); }, @@ -84,13 +84,13 @@ it('uses the blacklist to avoid copying properties on the first level', () => { }); it('does not keep the prototype by default when top level is object', () => { - // @ts-ignore + // @ts-expect-error const sourceObject = new (function () {})(); - // @ts-ignore + // @ts-expect-error sourceObject.nestedObject = new (function () {})(); - // @ts-ignore + // @ts-expect-error sourceObject.nestedArray = new (function () { - // @ts-ignore + // @ts-expect-error this.length = 0; })(); @@ -124,9 +124,9 @@ it('does not keep the prototype by default when top level is object', () => { it('does not keep the prototype by default when top level is array', () => { const spy = jest.spyOn(Array, 'isArray').mockImplementation(() => true); - // @ts-ignore + // @ts-expect-error const sourceArray = new (function () { - // @ts-ignore + // @ts-expect-error this.length = 0; })(); @@ -142,9 +142,9 @@ it('does not keep the prototype by default when top level is array', () => { it('does not keep the prototype of arrays when keepPrototype = false', () => { const spy = jest.spyOn(Array, 'isArray').mockImplementation(() => true); - // @ts-ignore + // @ts-expect-error const sourceArray = new (function () { - // @ts-ignore + // @ts-expect-error this.length = 0; })(); @@ -160,9 +160,9 @@ it('does not keep the prototype of arrays when keepPrototype = false', () => { it('keeps the prototype of arrays when keepPrototype = true', () => { const spy = jest.spyOn(Array, 'isArray').mockImplementation(() => true); - // @ts-ignore + // @ts-expect-error const sourceArray = new (function () { - // @ts-ignore + // @ts-expect-error this.length = 0; })(); @@ -173,13 +173,13 @@ it('keeps the prototype of arrays when keepPrototype = true', () => { }); it('does not keep the prototype for objects when keepPrototype = false', () => { - // @ts-ignore + // @ts-expect-error const sourceobject = new (function () {})(); - // @ts-ignore + // @ts-expect-error sourceobject.nestedObject = new (function () {})(); - // @ts-ignore + // @ts-expect-error sourceobject.nestedArray = new (function () { - // @ts-ignore + // @ts-expect-error this.length = 0; })(); @@ -210,13 +210,13 @@ it('does not keep the prototype for objects when keepPrototype = false', () => { }); it('keeps the prototype for objects when keepPrototype = true', () => { - // @ts-ignore + // @ts-expect-error const sourceObject = new (function () {})(); - // @ts-ignore + // @ts-expect-error sourceObject.nestedObject = new (function () {})(); - // @ts-ignore + // @ts-expect-error sourceObject.nestedArray = new (function () { - // @ts-ignore + // @ts-expect-error this.length = 0; })(); diff --git a/packages/jest-util/src/__tests__/installCommonGlobals.test.ts b/packages/jest-util/src/__tests__/installCommonGlobals.test.ts index d61cd59389f8..d3f57912a483 100644 --- a/packages/jest-util/src/__tests__/installCommonGlobals.test.ts +++ b/packages/jest-util/src/__tests__/installCommonGlobals.test.ts @@ -16,7 +16,7 @@ function getGlobal(): NodeJS.Global { beforeEach(() => { fake = jest.fn(); - // @ts-ignore + // @ts-expect-error global.DTRACE_NET_SERVER_CONNECTION = fake; installCommonGlobals = require('../installCommonGlobals').default; diff --git a/packages/jest-util/src/convertDescriptorToString.ts b/packages/jest-util/src/convertDescriptorToString.ts index 50324d218204..c10ea8bf7f83 100644 --- a/packages/jest-util/src/convertDescriptorToString.ts +++ b/packages/jest-util/src/convertDescriptorToString.ts @@ -29,7 +29,7 @@ export default function convertDescriptorToString< const stringified = descriptor.toString(); const typeDescriptorMatch = stringified.match(/class|function/); const indexOfNameSpace = - // @ts-ignore: typeDescriptorMatch exists + // @ts-expect-error: typeDescriptorMatch exists typeDescriptorMatch.index + typeDescriptorMatch[0].length; const indexOfNameAfterSpace = stringified.search(/\(|\{/); const name = stringified.substring(indexOfNameSpace, indexOfNameAfterSpace); diff --git a/packages/jest-util/src/installCommonGlobals.ts b/packages/jest-util/src/installCommonGlobals.ts index e711df3ae2c4..ece4a40649d0 100644 --- a/packages/jest-util/src/installCommonGlobals.ts +++ b/packages/jest-util/src/installCommonGlobals.ts @@ -55,9 +55,9 @@ export default function ( // Forward some APIs. DTRACE.forEach(dtrace => { - // @ts-ignore: no index + // @ts-expect-error: no index globalObject[dtrace] = function (...args: Array) { - // @ts-ignore: no index + // @ts-expect-error: no index return global[dtrace].apply(this, args); }; }); diff --git a/packages/jest-util/src/setGlobal.ts b/packages/jest-util/src/setGlobal.ts index 012b3bd721ae..f840a7f4bae4 100644 --- a/packages/jest-util/src/setGlobal.ts +++ b/packages/jest-util/src/setGlobal.ts @@ -10,6 +10,6 @@ export default ( key: string, value: unknown, ): void => { - // @ts-ignore: no index + // @ts-expect-error: no index globalToMutate[key] = value; }; diff --git a/packages/jest-validate/src/condition.ts b/packages/jest-validate/src/condition.ts index b8bb69c763b6..9ae9be24416c 100644 --- a/packages/jest-validate/src/condition.ts +++ b/packages/jest-validate/src/condition.ts @@ -24,7 +24,7 @@ function validationConditionSingle( export function getValues(validOption: T): Array { if ( Array.isArray(validOption) && - // @ts-ignore + // @ts-expect-error validOption[MULTIPLE_VALID_OPTIONS_SYMBOL] ) { return validOption; @@ -43,7 +43,7 @@ export function multipleValidOptions>( ...args: T ): T[number] { const options = [...args]; - // @ts-ignore + // @ts-expect-error options[MULTIPLE_VALID_OPTIONS_SYMBOL] = true; return options; diff --git a/packages/jest-worker/src/index.ts b/packages/jest-worker/src/index.ts index 4107f6c4657a..5858f6c7f90e 100644 --- a/packages/jest-worker/src/index.ts +++ b/packages/jest-worker/src/index.ts @@ -26,7 +26,7 @@ function getExposedMethods( const module: Function | Record = require(workerPath); exposedMethods = Object.keys(module).filter( - // @ts-ignore: no index + // @ts-expect-error: no index name => typeof module[name] === 'function', ); @@ -82,7 +82,7 @@ export default class JestWorker { }; if (this._options.WorkerPool) { - // @ts-ignore: constructor target any? + // @ts-expect-error: constructor target any? this._workerPool = new this._options.WorkerPool( workerPath, workerPoolOptions, @@ -113,7 +113,7 @@ export default class JestWorker { throw new TypeError('Cannot define a method called ' + name); } - // @ts-ignore: dynamic extension of the class instance is expected. + // @ts-expect-error: dynamic extension of the class instance is expected. this[name] = this._callFunctionWithArgs.bind(this, name); }); } diff --git a/packages/jest-worker/src/workers/ChildProcessWorker.ts b/packages/jest-worker/src/workers/ChildProcessWorker.ts index 8410fdbf0cf7..375b2788b3e8 100644 --- a/packages/jest-worker/src/workers/ChildProcessWorker.ts +++ b/packages/jest-worker/src/workers/ChildProcessWorker.ts @@ -167,7 +167,7 @@ export default class ChildProcessWorker implements WorkerInterface { if (error != null && typeof error === 'object') { const extra = error; - // @ts-ignore: no index + // @ts-expect-error: no index const NativeCtor = global[response[1]]; const Ctor = typeof NativeCtor === 'function' ? NativeCtor : Error; @@ -176,7 +176,7 @@ export default class ChildProcessWorker implements WorkerInterface { error.stack = response[3]; for (const key in extra) { - // @ts-ignore: adding custom properties to errors. + // @ts-expect-error: adding custom properties to errors. error[key] = extra[key]; } } @@ -187,7 +187,7 @@ export default class ChildProcessWorker implements WorkerInterface { case PARENT_MESSAGE_SETUP_ERROR: error = new Error('Error when calling setup: ' + response[2]); - // @ts-ignore: adding custom properties to errors. + // @ts-expect-error: adding custom properties to errors. error.type = response[1]; error.stack = response[3]; diff --git a/packages/jest-worker/src/workers/NodeThreadsWorker.ts b/packages/jest-worker/src/workers/NodeThreadsWorker.ts index 64837106eda2..49f98be9d696 100644 --- a/packages/jest-worker/src/workers/NodeThreadsWorker.ts +++ b/packages/jest-worker/src/workers/NodeThreadsWorker.ts @@ -145,7 +145,7 @@ export default class ExperimentalWorker implements WorkerInterface { if (error != null && typeof error === 'object') { const extra = error; - // @ts-ignore: no index + // @ts-expect-error: no index const NativeCtor = global[response[1]]; const Ctor = typeof NativeCtor === 'function' ? NativeCtor : Error; @@ -154,7 +154,7 @@ export default class ExperimentalWorker implements WorkerInterface { error.stack = response[3]; for (const key in extra) { - // @ts-ignore: no index + // @ts-expect-error: no index error[key] = extra[key]; } } @@ -164,7 +164,7 @@ export default class ExperimentalWorker implements WorkerInterface { case PARENT_MESSAGE_SETUP_ERROR: error = new Error('Error when calling setup: ' + response[2]); - // @ts-ignore: adding custom properties to errors. + // @ts-expect-error: adding custom properties to errors. error.type = response[1]; error.stack = response[3]; diff --git a/packages/pretty-format/src/__tests__/prettyFormat.test.ts b/packages/pretty-format/src/__tests__/prettyFormat.test.ts index ddd99fc0ec7b..b217830a1c5f 100644 --- a/packages/pretty-format/src/__tests__/prettyFormat.test.ts +++ b/packages/pretty-format/src/__tests__/prettyFormat.test.ts @@ -14,7 +14,7 @@ function returnArguments(..._args: Array) { class MyArray extends Array {} function MyObject(value: unknown) { - // @ts-ignore + // @ts-expect-error this.name = value; } @@ -508,7 +508,7 @@ describe('prettyFormat()', () => { 'map non-empty': new Map([['name', 'value']]), 'object literal empty': {}, 'object literal non-empty': {name: 'value'}, - // @ts-ignore + // @ts-expect-error 'object with constructor': new MyObject('value'), 'object without constructor': Object.create(null), 'set empty': new Set(), @@ -540,7 +540,7 @@ describe('prettyFormat()', () => { it('throws on invalid options', () => { expect(() => { - // @ts-ignore + // @ts-expect-error prettyFormat({}, {invalidOption: true}); }).toThrow(); }); @@ -811,7 +811,7 @@ describe('prettyFormat()', () => { 'map non-empty': new Map([['name', 'value']]), 'object literal empty': {}, 'object literal non-empty': {name: 'value'}, - // @ts-ignore + // @ts-expect-error 'object with constructor': new MyObject('value'), 'object without constructor': Object.create(null), 'set empty': new Set(), diff --git a/packages/pretty-format/src/__tests__/react.test.tsx b/packages/pretty-format/src/__tests__/react.test.tsx index 88a64c3f3eee..e2cdad9c9a10 100644 --- a/packages/pretty-format/src/__tests__/react.test.tsx +++ b/packages/pretty-format/src/__tests__/react.test.tsx @@ -634,7 +634,7 @@ test('throws if theme option is null', () => { 'Hello, Mouse!', ); expect(() => { - // @ts-ignore + // @ts-expect-error formatElement(jsx, { highlight: true, theme: null, @@ -649,7 +649,7 @@ test('throws if theme option is not of type "object"', () => { {style: 'color:red'}, 'Hello, Mouse!', ); - // @ts-ignore + // @ts-expect-error formatElement(jsx, { highlight: true, theme: 'beautiful', diff --git a/scripts/verifyOldTs.js b/scripts/verifyOldTs.js index 47c93fbc8ab4..cfa8b8c3ddd8 100644 --- a/scripts/verifyOldTs.js +++ b/scripts/verifyOldTs.js @@ -30,9 +30,14 @@ const tsConfig = { }; const cwd = tempy.directory(); +const tsVersion = '3.8'; + try { execa.sync('yarn', ['init', '--yes'], {cwd, stdio: 'inherit'}); - execa.sync('yarn', ['add', 'typescript@~3.8'], {cwd, stdio: 'inherit'}); + execa.sync('yarn', ['add', `typescript@~${tsVersion}`], { + cwd, + stdio: 'inherit', + }); fs.writeFileSync( path.join(cwd, 'tsconfig.json'), JSON.stringify(tsConfig, null, 2), @@ -44,7 +49,9 @@ try { execa.sync('yarn', ['tsc', '--project', '.'], {cwd, stdio: 'inherit'}); console.log( - chalk.inverse.green(' Successfully compiled Jest with TypeScript 3.4 '), + chalk.inverse.green( + ` Successfully compiled Jest with TypeScript ${tsVersion} `, + ), ); } finally { rimraf.sync(cwd); diff --git a/yarn.lock b/yarn.lock index 624b75f1a1eb..8e3a6ddb5df3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13301,10 +13301,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@*, typescript@^3.8.2: - version "3.8.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061" - integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w== +typescript@*, typescript@^3.9.2: + version "3.9.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.2.tgz#64e9c8e9be6ea583c54607677dd4680a1cf35db9" + integrity sha512-q2ktq4n/uLuNNShyayit+DTobV2ApPEo/6so68JaD5ojvc/6GClBipedB9zNWYxRSAlZXAe405Rlijzl6qDiSw== ua-parser-js@^0.7.18: version "0.7.21"