Skip to content

Commit b3d4a1d

Browse files
authoredJul 13, 2022
refactor(jest-mock): simplify PropertyLikeKeys utility type (#13020)
1 parent 3d94b58 commit b3d4a1d

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed
 

‎CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
- `[jest-changed-files]` Fix a lock-up after repeated invocations ([#12757](https://github.com/facebook/jest/issues/12757))
1010
- `[@jest/expect-utils]` Fix deep equality of ImmutableJS OrderedSets ([#12977](https://github.com/facebook/jest/pull/12977))
11-
- `[jest-mock]` Add index signature support for `spyOn` types ([#13013](https://github.com/facebook/jest/pull/13013))
11+
- `[jest-mock]` Add index signature support for `spyOn` types ([#13013](https://github.com/facebook/jest/pull/13013), [#13020](https://github.com/facebook/jest/pull/13020))
1212
- `[jest-snapshot]` Fix indentation of awaited inline snapshots ([#12986](https://github.com/facebook/jest/pull/12986))
1313

1414
### Chore & Maintenance

‎packages/jest-mock/__typetests__/mock-functions.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ expectType<SpyInstance<typeof indexSpiedObject.methodE>>(
374374
spyOn(indexSpiedObject, 'methodE'),
375375
);
376376

377-
expectError(spyOn(indexSpiedObject, 'propertyA'));
378-
379377
expectType<SpyInstance<() => {a: string}>>(
380378
spyOn(indexSpiedObject, 'propertyA', 'get'),
381379
);

‎packages/jest-mock/__typetests__/utility-types.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ type IndexObject = {
8686

8787
methodA(): void;
8888
methodB(b: string): boolean;
89-
methodC: (c: number) => true;
89+
methodC: (c: number) => boolean;
9090

91-
propertyA: {a: 123};
92-
propertyB: {b: 'value'};
91+
propertyA: {a: number};
92+
propertyB: {b: string};
9393
};
9494

9595
// ClassLike
@@ -142,6 +142,6 @@ declare const objectProperties: PropertyLikeKeys<SomeObject>;
142142
declare const indexObjectProperties: PropertyLikeKeys<IndexObject>;
143143

144144
expectType<'propertyA' | 'propertyB' | 'propertyC'>(classProperties);
145-
expectType<string>(indexClassProperties);
145+
expectType<string | number>(indexClassProperties);
146146
expectType<'propertyA' | 'propertyB' | 'someClassInstance'>(objectProperties);
147-
expectType<string>(indexObjectProperties);
147+
expectType<string | number>(indexObjectProperties);

‎packages/jest-mock/src/index.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@ export type MethodLikeKeys<T> = keyof {
4242
[K in keyof T as T[K] extends FunctionLike ? K : never]: T[K];
4343
};
4444

45-
export type PropertyLikeKeys<T> = {
46-
[K in keyof T]: T[K] extends FunctionLike
47-
? never
48-
: T[K] extends ClassLike
49-
? never
50-
: K;
51-
}[keyof T];
45+
export type PropertyLikeKeys<T> = Exclude<
46+
keyof T,
47+
ConstructorLikeKeys<T> | MethodLikeKeys<T>
48+
>;
5249

5350
// TODO Figure out how to replace this with TS ConstructorParameters utility type
5451
// https://www.typescriptlang.org/docs/handbook/utility-types.html#constructorparameterstype

0 commit comments

Comments
 (0)
Please sign in to comment.