mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
shared/ typescript types dir server-commands
This commit is contained in:
parent
6b5f72beda
commit
bf54587a3e
242 changed files with 228 additions and 172 deletions
45
shared/typescript-utils/types.ts
Normal file
45
shared/typescript-utils/types.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* eslint-disable @typescript-eslint/array-type */
|
||||
|
||||
export type FunctionPropertyNames<T> = {
|
||||
[K in keyof T]: T[K] extends Function ? K : never
|
||||
}[keyof T]
|
||||
|
||||
export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>
|
||||
|
||||
export type AttributesOnly<T> = {
|
||||
[K in keyof T]: T[K] extends Function ? never : T[K]
|
||||
}
|
||||
|
||||
export type PickWith<T, KT extends keyof T, V> = {
|
||||
[P in KT]: T[P] extends V ? V : never
|
||||
}
|
||||
|
||||
export type PickWithOpt<T, KT extends keyof T, V> = {
|
||||
[P in KT]?: T[P] extends V ? V : never
|
||||
}
|
||||
|
||||
// https://github.com/krzkaczor/ts-essentials Rocks!
|
||||
export type DeepPartial<T> = {
|
||||
[P in keyof T]?: T[P] extends Array<infer U>
|
||||
? Array<DeepPartial<U>>
|
||||
: T[P] extends ReadonlyArray<infer U>
|
||||
? ReadonlyArray<DeepPartial<U>>
|
||||
: DeepPartial<T[P]>
|
||||
}
|
||||
|
||||
type Primitive = string | Function | number | boolean | Symbol | undefined | null
|
||||
export type DeepOmitHelper<T, K extends keyof T> = {
|
||||
[P in K]: // extra level of indirection needed to trigger homomorhic behavior
|
||||
T[P] extends infer TP // distribute over unions
|
||||
? TP extends Primitive
|
||||
? TP // leave primitives and functions alone
|
||||
: TP extends any[]
|
||||
? DeepOmitArray<TP, K> // Array special handling
|
||||
: DeepOmit<TP, K>
|
||||
: never
|
||||
}
|
||||
export type DeepOmit<T, K> = T extends Primitive ? T : DeepOmitHelper<T, Exclude<keyof T, K>>
|
||||
|
||||
export type DeepOmitArray<T extends any[], K> = {
|
||||
[P in keyof T]: DeepOmit<T[P], K>
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue