/
types.ts
37 lines (31 loc) · 1 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type {MockInstance} from './index';
type ClassLike = {new (...args: any): any};
type FunctionLike = (...args: any) => any;
type MockedClass<T extends ClassLike> = MockInstance<
(...args: ConstructorParameters<T>) => Mocked<InstanceType<T>>
> & {
prototype: T extends {prototype: any} ? Mocked<T['prototype']> : never;
} & MockedObject<T>;
type MockedFunction<T extends FunctionLike> = MockInstance<T> & MockedObject<T>;
type MockedObject<T> = {
[K in keyof T]: T[K] extends ClassLike
? MockedClass<T[K]>
: T[K] extends FunctionLike
? MockedFunction<T[K]>
: T[K] extends object
? MockedObject<T[K]>
: T[K];
} & T;
export type Mocked<T> = T extends ClassLike
? MockedClass<T>
: T extends FunctionLike
? MockedFunction<T>
: T extends object
? MockedObject<T>
: T;