Skip to content

Commit ccea646

Browse files
JoshRosensteinSimenB
authored andcommitted
General Type Maintenance (#8462)
1 parent e224f2d commit ccea646

File tree

44 files changed

+126
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+126
-98
lines changed

packages/babel-plugin-jest-hoist/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ const IDVisitor = {
8888
blacklist: ['TypeAnnotation', 'TSTypeAnnotation', 'TSTypeReference'],
8989
};
9090

91-
const FUNCTIONS: {
92-
[key: string]: (args: Array<NodePath>) => boolean;
93-
} = Object.create(null);
91+
const FUNCTIONS: Record<
92+
string,
93+
(args: Array<NodePath>) => boolean
94+
> = Object.create(null);
9495

9596
FUNCTIONS.mock = (args: Array<NodePath>) => {
9697
if (args.length === 1) {

packages/expect/src/asymmetricMatchers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ class ObjectContaining extends AsymmetricMatcher<Record<string, any>> {
158158
for (const property in this.sample) {
159159
if (
160160
hasProperty(other, property) &&
161-
equals((this.sample as any)[property], other[property]) &&
162-
!emptyObject((this.sample as any)[property]) &&
161+
equals(this.sample[property], other[property]) &&
162+
!emptyObject(this.sample[property]) &&
163163
!emptyObject(other[property])
164164
) {
165165
return false;
@@ -171,7 +171,7 @@ class ObjectContaining extends AsymmetricMatcher<Record<string, any>> {
171171
for (const property in this.sample) {
172172
if (
173173
!hasProperty(other, property) ||
174-
!equals((this.sample as any)[property], other[property])
174+
!equals(this.sample[property], other[property])
175175
) {
176176
return false;
177177
}

packages/expect/src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ const makeThrowingMatcher = (
299299

300300
const handlError = (error: Error) => {
301301
if (
302-
(matcher as any)[INTERNAL_MATCHER_FLAG] === true &&
302+
matcher[INTERNAL_MATCHER_FLAG] === true &&
303303
!(error instanceof JestAssertionError) &&
304304
error.name !== 'PrettyFormatPluginError' &&
305305
// Guard for some environments (browsers) that do not support this feature.
@@ -314,10 +314,7 @@ const makeThrowingMatcher = (
314314
let potentialResult: ExpectationResult;
315315

316316
try {
317-
potentialResult = matcher.apply(
318-
matcherContext,
319-
([actual] as any).concat(args),
320-
);
317+
potentialResult = matcher.call(matcherContext, actual, ...args);
321318

322319
if (isPromise(potentialResult)) {
323320
const asyncResult = potentialResult as AsyncExpectationResult;
@@ -340,7 +337,7 @@ const makeThrowingMatcher = (
340337
};
341338

342339
expect.extend = (matchers: MatchersObject): void =>
343-
setMatchers(matchers, false, expect as any);
340+
setMatchers(matchers, false, expect);
344341

345342
expect.anything = anything;
346343
expect.any = any;

packages/expect/src/jasmineUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ function keys(
208208
return keys.concat(
209209
(Object.getOwnPropertySymbols(o) as Array<any>).filter(
210210
symbol =>
211-
(Object.getOwnPropertyDescriptor(o, symbol) as any).enumerable,
211+
(Object.getOwnPropertyDescriptor(o, symbol) as PropertyDescriptor)
212+
.enumerable,
212213
),
213214
);
214215
})(obj);

packages/expect/src/jestMatchersObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const JEST_MATCHERS_OBJECT = Symbol.for('$$jest-matchers-object');
1717
// Jest may override the stack trace of Errors thrown by internal matchers.
1818
export const INTERNAL_MATCHER_FLAG = Symbol.for('$$jest-internal-matcher');
1919

20-
if (!(global as any)[JEST_MATCHERS_OBJECT]) {
20+
if (!global.hasOwnProperty(JEST_MATCHERS_OBJECT)) {
2121
Object.defineProperty(global, JEST_MATCHERS_OBJECT, {
2222
value: {
2323
matchers: Object.create(null),

packages/expect/src/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
import {Config} from '@jest/types';
99
import * as jestMatcherUtils from 'jest-matcher-utils';
10+
import {INTERNAL_MATCHER_FLAG} from './jestMatchersObject';
1011

1112
export type SyncExpectationResult = {
1213
pass: boolean;
@@ -17,11 +18,10 @@ export type AsyncExpectationResult = Promise<SyncExpectationResult>;
1718

1819
export type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
1920

20-
export type RawMatcherFn = (
21-
received: any,
22-
expected: any,
23-
options?: any,
24-
) => ExpectationResult;
21+
export type RawMatcherFn = {
22+
(received: any, expected: any, options?: any): ExpectationResult;
23+
[INTERNAL_MATCHER_FLAG]?: boolean;
24+
};
2525

2626
export type ThrowingMatcherFn = (actual: any) => void;
2727
export type PromiseMatcherFn = (actual: any) => Promise<void>;

packages/expect/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const hasOwnProperty = (object: object, key: string) =>
4949
hasGetterFromConstructor(object, key);
5050

5151
export const getPath = (
52-
object: object,
52+
object: Record<string, any>,
5353
propertyPath: string | Array<string>,
5454
): GetPath => {
5555
if (!Array.isArray(propertyPath)) {
@@ -59,7 +59,7 @@ export const getPath = (
5959
if (propertyPath.length) {
6060
const lastProp = propertyPath.length === 1;
6161
const prop = propertyPath[0];
62-
const newObject = (object as any)[prop];
62+
const newObject = object[prop];
6363

6464
if (!lastProp && (newObject === null || newObject === undefined)) {
6565
// This is not the last prop in the chain. If we keep recursing it will

packages/jest-circus/src/formatNodeAssertErrors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ interface AssertionErrorWithStack extends AssertionError {
2020
stack: string;
2121
}
2222

23-
const assertOperatorsMap: {[key: string]: string} = {
23+
const assertOperatorsMap: Record<string, string> = {
2424
'!=': 'notEqual',
2525
'!==': 'notStrictEqual',
2626
'==': 'equal',
2727
'===': 'strictEqual',
2828
};
2929

30-
const humanReadableOperators: {[key: string]: string} = {
30+
const humanReadableOperators: Record<string, string> = {
3131
deepEqual: 'to deeply equal',
3232
deepStrictEqual: 'to deeply and strictly equal',
3333
equal: 'to be equal',

packages/jest-cli/src/init/generate_config_file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const stringifyOption = (
3131
);
3232
};
3333

34-
const generateConfigFile = (results: {[key: string]: unknown}): string => {
34+
const generateConfigFile = (results: Record<string, unknown>): string => {
3535
const {coverage, clearMocks, environment} = results;
3636

3737
const overrides: Record<string, any> = {};

packages/jest-cli/src/init/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ import {Config} from '@jest/types';
99

1010
export type ProjectPackageJson = {
1111
jest?: Partial<Config.InitialOptions>;
12-
scripts?: {[key: string]: string};
12+
scripts?: Record<string, string>;
1313
};

0 commit comments

Comments
 (0)