-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
common_prop_keys.ts
38 lines (34 loc) · 1.28 KB
/
common_prop_keys.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
import type { CommonPropKeys as ArrayCommonPropKeys } from '../array/array_plus.common_prop_keys.js'
import type { KeyTypes } from '../object/KeyTypes.js'
import type { CommonPropKeys as TupleCommonPropKeys } from './tuple_plus.common_prop_keys.js'
/**
* ⚗️ *transform*
* 🔢 *customization*
*
* Gets the common property keys of the elements in tuple or array `T`.
*
* @example
* ```ts
* import { CommonPropKeys } from 'type-plus'
*
* type R = CommonPropKeys<[{ a: number }, { b: number }]> // never
* type R = CommonPropKeys<[{ a: number, c: 1 }, { b: number, c: 2 }]> // 'c'
* ```
*
* @typeParam Options['$never'] Return type when `T` is `never`.
* Default to `never`.
*/
export type CommonPropKeys<
T extends Record<KeyTypes, unknown>[],
Options extends CommonPropKeys.Options = CommonPropKeys.DefaultOptions
> = number extends T['length'] ? ArrayCommonPropKeys<T> : TupleCommonPropKeys<T, Options>
export namespace CommonPropKeys {
export interface Options extends TupleCommonPropKeys.Options {}
export interface DefaultOptions extends TupleCommonPropKeys.DefaultOptions {}
}
/**
* Gets the common property keys of the elements in `A`.
*
* @deprecated Please use `CommonPropKeys` instead.
*/
export type CommonKeys<A extends Record<KeyTypes, any>[]> = CommonPropKeys<A>