forked from jestjs/jest
/
utility-types.test.ts
51 lines (40 loc) · 1.18 KB
/
utility-types.test.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* 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 {expectType} from 'tsd-lite';
import type {MethodKeys, PropertyKeys} from 'jest-mock';
interface SomeObject {
methodA(): void;
methodB(a: string): number;
propertyA: number;
propertyB: string;
}
declare const objectMethods: MethodKeys<SomeObject>;
declare const objectProperties: PropertyKeys<SomeObject>;
expectType<'methodA' | 'methodB'>(objectMethods);
expectType<'propertyA' | 'propertyB'>(objectProperties);
class SomeClass {
propertyB = 123;
private _propertyC: undefined;
#propertyD = 'abc';
constructor(public propertyA: string) {}
methodA(): void {
return;
}
methodB(b: string): string {
return b;
}
get propertyC() {
return this._propertyC;
}
set propertyC(value) {
this._propertyC = value;
}
}
declare const classMethods: MethodKeys<SomeClass>;
declare const classProperties: PropertyKeys<SomeClass>;
expectType<'methodA' | 'methodB'>(classMethods);
expectType<'propertyA' | 'propertyB' | 'propertyC'>(classProperties);