]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/core-utils/miscs/types.ts
Try to reduce CSS size
[github/Chocobozzz/PeerTube.git] / shared / core-utils / miscs / types.ts
CommitLineData
a1587156
C
1/* eslint-disable @typescript-eslint/array-type */
2
453e83ea
C
3export type FunctionPropertyNames<T> = {
4 [K in keyof T]: T[K] extends Function ? K : never
5}[keyof T]
5224c394
C
6
7export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>
453e83ea 8
453e83ea
C
9export type PickWith<T, KT extends keyof T, V> = {
10 [P in KT]: T[P] extends V ? V : never
11}
12
13export type PickWithOpt<T, KT extends keyof T, V> = {
14 [P in KT]?: T[P] extends V ? V : never
15}
8424c402
C
16
17// https://github.com/krzkaczor/ts-essentials Rocks!
18export type DeepPartial<T> = {
19 [P in keyof T]?: T[P] extends Array<infer U>
20 ? Array<DeepPartial<U>>
21 : T[P] extends ReadonlyArray<infer U>
22 ? ReadonlyArray<DeepPartial<U>>
23 : DeepPartial<T[P]>
10a105f0 24}
67ed6552
C
25
26type Primitive = string | Function | number | boolean | Symbol | undefined | null
27export type DeepOmitHelper<T, K extends keyof T> = {
28 [P in K]: // extra level of indirection needed to trigger homomorhic behavior
29 T[P] extends infer TP // distribute over unions
30 ? TP extends Primitive
31 ? TP // leave primitives and functions alone
32 : TP extends any[]
33 ? DeepOmitArray<TP, K> // Array special handling
34 : DeepOmit<TP, K>
35 : never
36}
37export type DeepOmit<T, K> = T extends Primitive ? T : DeepOmitHelper<T, Exclude<keyof T, K>>
38
39export type DeepOmitArray<T extends any[], K> = {
40 [P in keyof T]: DeepOmit<T[P], K>
41}