diff --git a/.eslintrc.js b/.eslintrc.js index e97b295635ac..e8b92949990d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -21,6 +21,7 @@ module.exports = { plugins: ['@typescript-eslint/eslint-plugin'], rules: { '@typescript-eslint/array-type': ['error', 'generic'], + '@typescript-eslint/ban-types': 'error', '@typescript-eslint/no-unused-vars': [ 'error', {argsIgnorePattern: '^_'}, diff --git a/packages/expect/src/asymmetricMatchers.ts b/packages/expect/src/asymmetricMatchers.ts index 1742cf7711ae..f9907882de10 100644 --- a/packages/expect/src/asymmetricMatchers.ts +++ b/packages/expect/src/asymmetricMatchers.ts @@ -12,7 +12,7 @@ import {emptyObject} from './utils'; export class AsymmetricMatcher { protected sample: T; - $$typeof: Symbol; + $$typeof: symbol; inverse?: boolean; constructor(sample: T) { @@ -139,8 +139,8 @@ class ArrayContaining extends AsymmetricMatcher> { } } -class ObjectContaining extends AsymmetricMatcher { - constructor(sample: Object, inverse: boolean = false) { +class ObjectContaining extends AsymmetricMatcher> { + constructor(sample: Record, inverse: boolean = false) { super(sample); this.inverse = inverse; } @@ -245,9 +245,9 @@ export const arrayContaining = (sample: Array) => new ArrayContaining(sample); export const arrayNotContaining = (sample: Array) => new ArrayContaining(sample, true); -export const objectContaining = (sample: Object) => +export const objectContaining = (sample: Record) => new ObjectContaining(sample); -export const objectNotContaining = (sample: Object) => +export const objectNotContaining = (sample: Record) => new ObjectContaining(sample, true); export const stringContaining = (expected: string) => new StringContaining(expected); diff --git a/packages/expect/src/types.ts b/packages/expect/src/types.ts index 106abcb03995..42775048e22b 100644 --- a/packages/expect/src/types.ts +++ b/packages/expect/src/types.ts @@ -52,7 +52,7 @@ export type MatcherState = { }; }; -export type AsymmetricMatcher = Object; +export type AsymmetricMatcher = Record; export type MatchersObject = {[id: string]: RawMatcherFn}; export type Expect = { (expected: any): ExpectationObject; @@ -71,7 +71,7 @@ export type Expect = { any(expectedObject: any): AsymmetricMatcher; anything(): AsymmetricMatcher; arrayContaining(sample: Array): AsymmetricMatcher; - objectContaining(sample: Object): AsymmetricMatcher; + objectContaining(sample: Record): AsymmetricMatcher; stringContaining(expected: string): AsymmetricMatcher; stringMatching(expected: string | RegExp): AsymmetricMatcher; [id: string]: AsymmetricMatcher; diff --git a/packages/jest-circus/src/types.ts b/packages/jest-circus/src/types.ts index bdc9cc8f2d1c..04a854cfca3f 100644 --- a/packages/jest-circus/src/types.ts +++ b/packages/jest-circus/src/types.ts @@ -23,7 +23,7 @@ export type HookFn = (done?: DoneFn) => Promise | null | undefined; export type AsyncFn = TestFn | HookFn; export type SharedHookType = 'afterAll' | 'beforeAll'; export type HookType = SharedHookType | 'afterEach' | 'beforeEach'; -export type TestContext = Object; +export type TestContext = Record; export type Exception = any; // Since in JS anything can be thrown as an error. export type FormattedError = string; // String representation of error. export type Hook = { diff --git a/packages/jest-config/src/ReporterValidationErrors.ts b/packages/jest-config/src/ReporterValidationErrors.ts index 571f60605513..557d33c34234 100644 --- a/packages/jest-config/src/ReporterValidationErrors.ts +++ b/packages/jest-config/src/ReporterValidationErrors.ts @@ -40,7 +40,7 @@ export function createArrayReporterError( arrayReporter: Config.ReporterConfig, reporterIndex: number, valueIndex: number, - value: string | Object, + value: string | Record, expectedType: string, valueName: string, ) { diff --git a/packages/jest-diff/src/index.ts b/packages/jest-diff/src/index.ts index 8bcfa54b96e5..53c88fa62bd4 100644 --- a/packages/jest-diff/src/index.ts +++ b/packages/jest-diff/src/index.ts @@ -112,7 +112,11 @@ function sortSet(set: Set) { return new Set(Array.from(set.values()).sort()); } -function compareObjects(a: Object, b: Object, options?: JestDiffOptions) { +function compareObjects( + a: Record, + b: Record, + options?: JestDiffOptions, +) { let diffMessage; let hasThrown = false; diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index a29270083abb..f1b262c6ce98 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -49,7 +49,7 @@ export interface Jest { * * @deprecated Use `expect.extend` instead */ - addMatchers(matchers: Object): void; + addMatchers(matchers: Record): void; /** * Disables automatic mocking in the module loader. */ diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 88a0aa893d00..33e896b8b421 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -1108,7 +1108,7 @@ class DuplicateError extends Error { } } -function copy(object: T): T { +function copy>(object: T): T { return Object.assign(Object.create(null), object); } diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index b39c2b9f7ed9..83ec7e42e936 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -385,7 +385,7 @@ class ModuleMockerClass { this._invocationCallCounter = 1; } - private _getSlots(object?: Object): Array { + private _getSlots(object?: Record): Array { if (!object) { return []; } @@ -480,7 +480,7 @@ class ModuleMockerClass { private _makeComponent>( metadata: JestMock.MockFunctionMetadata, restore?: () => void, - ): Object; + ): Record; private _makeComponent>( metadata: JestMock.MockFunctionMetadata, restore?: () => void, @@ -504,7 +504,13 @@ class ModuleMockerClass { private _makeComponent>( metadata: JestMock.MockFunctionMetadata, restore?: () => void, - ): Object | Array | RegExp | T | undefined | Mock { + ): + | Record + | Array + | RegExp + | T + | undefined + | Mock { if (metadata.type === 'object') { return new this._environmentGlobal.Object(); } else if (metadata.type === 'array') { @@ -812,7 +818,7 @@ class ModuleMockerClass { callbacks: Array, refs: { [key: string]: - | Object + | Record | Array | RegExp | T diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index ef1a43efc119..83b327d12786 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -988,7 +988,7 @@ class Runtime { }; const jestObject: Jest = { - addMatchers: (matchers: Object) => + addMatchers: (matchers: Record) => this._environment.global.jasmine.addMatchers(matchers), advanceTimersByTime: (msToRun: number) => _getFakeTimers().advanceTimersByTime(msToRun), diff --git a/packages/jest-source-map/src/__tests__/getCallsite.test.ts b/packages/jest-source-map/src/__tests__/getCallsite.test.ts index f375645d679d..ecd017476e47 100644 --- a/packages/jest-source-map/src/__tests__/getCallsite.test.ts +++ b/packages/jest-source-map/src/__tests__/getCallsite.test.ts @@ -41,7 +41,7 @@ describe('getCallsite', () => { const sourceMapLine = 2; // @ts-ignore SourceMap.SourceMapConsumer = class { - originalPositionFor(params: Object) { + originalPositionFor(params: Record) { expect(params).toMatchObject({ column: expect.any(Number), line: expect.any(Number), diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index cffb4ba74e32..45cea095571d 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -21,7 +21,7 @@ export type HasteConfig = { export type ReporterConfig = [string, {[key: string]: unknown}]; -export type ConfigGlobals = Object; +export type ConfigGlobals = Record; export type DefaultOptions = { automock: boolean; @@ -80,7 +80,7 @@ export type DefaultOptions = { skipFilter: boolean; snapshotSerializers: Array; testEnvironment: string; - testEnvironmentOptions: Object; + testEnvironmentOptions: Record; testFailureExitCode: string | number; testLocationInResults: boolean; testMatch: Array; @@ -186,7 +186,7 @@ export type InitialOptions = { snapshotSerializers?: Array; errorOnDeprecated?: boolean; testEnvironment?: string; - testEnvironmentOptions?: Object; + testEnvironmentOptions?: Record; testFailureExitCode?: string | number; testLocationInResults?: boolean; testMatch?: Array; @@ -210,7 +210,7 @@ export type InitialOptions = { watch?: boolean; watchAll?: boolean; watchman?: boolean; - watchPlugins?: Array; + watchPlugins?: Array]>; }; export type SnapshotUpdateState = 'all' | 'new' | 'none'; @@ -301,7 +301,7 @@ export type GlobalConfig = { watchPlugins: | Array<{ path: string; - config: Object; + config: Record; }> | null | undefined; @@ -349,7 +349,7 @@ export type ProjectConfig = { snapshotResolver: Path | null | undefined; snapshotSerializers: Array; testEnvironment: string; - testEnvironmentOptions: Object; + testEnvironmentOptions: Record; testMatch: Array; testLocationInResults: boolean; testPathIgnorePatterns: Array; diff --git a/packages/jest-types/src/TestResult.ts b/packages/jest-types/src/TestResult.ts index caa976e84a28..4c9940e4f705 100644 --- a/packages/jest-types/src/TestResult.ts +++ b/packages/jest-types/src/TestResult.ts @@ -164,7 +164,7 @@ export type CodeCoverageReporter = any; export type CodeCoverageFormatter = ( coverage: CoverageMapData | null | undefined, reporter: CodeCoverageReporter, -) => Object | null | undefined; +) => Record | null | undefined; export type UncheckedSnapshot = { filePath: string; diff --git a/packages/jest-util/src/createProcessObject.ts b/packages/jest-util/src/createProcessObject.ts index b5be6442fe8b..f6d5b65843a8 100644 --- a/packages/jest-util/src/createProcessObject.ts +++ b/packages/jest-util/src/createProcessObject.ts @@ -19,7 +19,7 @@ function createProcessEnv(): NodeJS.ProcessEnv { return deepCyclicCopy(process.env); } - const proto: Object = Object.getPrototypeOf(process.env); + const proto: Record = Object.getPrototypeOf(process.env); const real = Object.create(proto); const lookup: typeof process.env = {}; diff --git a/packages/jest-worker/src/index.ts b/packages/jest-worker/src/index.ts index 6e8aa4f839ba..a7688e99ebb8 100644 --- a/packages/jest-worker/src/index.ts +++ b/packages/jest-worker/src/index.ts @@ -18,7 +18,7 @@ function getExposedMethods( // If no methods list is given, try getting it by auto-requiring the module. if (!exposedMethods) { - const module: Function | Object = require(workerPath); + const module: Function | Record = require(workerPath); exposedMethods = Object.keys(module).filter( // @ts-ignore: no index diff --git a/packages/pretty-format/src/collections.ts b/packages/pretty-format/src/collections.ts index 305e5c0da3d6..c9139d1e7331 100644 --- a/packages/pretty-format/src/collections.ts +++ b/packages/pretty-format/src/collections.ts @@ -8,7 +8,7 @@ import {Config, Printer, Refs} from './types'; -const getKeysOfEnumerableProperties = (object: Object) => { +const getKeysOfEnumerableProperties = (object: Record) => { const keys: Array = Object.keys(object).sort(); if (Object.getOwnPropertySymbols) { @@ -168,7 +168,7 @@ export function printListItems( * without surrounding punctuation (for example, braces) */ export function printObjectProperties( - val: Object, + val: Record, config: Config, indentation: string, depth: number, diff --git a/packages/pretty-format/src/plugins/ReactTestComponent.ts b/packages/pretty-format/src/plugins/ReactTestComponent.ts index c380fbfc3e81..bdb8c7fe072e 100644 --- a/packages/pretty-format/src/plugins/ReactTestComponent.ts +++ b/packages/pretty-format/src/plugins/ReactTestComponent.ts @@ -8,9 +8,9 @@ import {Config, Printer, NewPlugin, Refs} from '../types'; export type ReactTestObject = { - $$typeof: Symbol; + $$typeof: symbol; type: string; - props?: Object; + props?: Record; children?: null | Array; };