forked from material-components/material-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys.d.ts
57 lines (53 loc) · 1.47 KB
/
keys.d.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
52
53
54
55
56
57
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Retrieve all keys from type `T` and extract those whose value types are
* assignable to `V`.
*
* @template T The type to retrieve keys from.
* @template V The extracted keys' value type.
*/
export type ExtractKeysOfType<T extends object, V> = {
[K in keyof T]: T[K] extends V ? K : never;
}[keyof T];
/**
* Retrieve all keys from type `T` and exclude those whose value types are
* assignable to `V`.
*
* @template T The type to retrieve keys from.
* @template V The excluded keys' value type.
*/
export type ExcludeKeysOfType<T extends object, V> = {
[K in keyof T]: T[K] extends V ? never : K;
}[keyof T];
/**
* Retrieves all keys from type `T` whose value types are function.
*
* @template T The type to retrieve keys from.
* @example
* class Foo {
* property = false;
* method() {}
* }
*
* type AllKeys = keyof Foo; // 'property'|'method'
* type FooFunctionKeys = FunctionKeys<Foo>; // 'method'
*/
export type FunctionKeys<T extends object> = ExtractKeysOfType<T, Function>;
/**
* Retrieves all keys from type `T` whose value types are not functions.
*
* @template T The type to retrieve keys from.
* @example
* interface Foo {
* property = false;
* method() {}
* }
*
* type AllKeys = keyof Foo; // 'property'|'method'
* type FooFunctionKeys = PropertyKeys<Foo>; // 'property'
*/
export type PropertyKeys<T extends object> = ExcludeKeysOfType<T, Function>;