@peersyst/react-types
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -16,6 +16,4 @@ import { CSSProperties } from "react"; | ||
*/ | ||
export type OverridableStringUnion< | ||
T extends string | number, | ||
U = Record<string, any>, | ||
> = GenerateStringUnion<Overwrite<Record<T, true>, U>>; | ||
export type OverridableStringUnion<T extends string | number, U = Record<string, any>> = | ||
GenerateStringUnion<Overwrite<Record<T, true>, U>>; | ||
@@ -87,11 +85,64 @@ /** | ||
/** | ||
* Gets all keys with type undefined of T | ||
* Get all keys with type T from O | ||
*/ | ||
type UndefinedKeys<T> = { | ||
[K in keyof T]: T[K] extends undefined ? K : never; | ||
type TypeKeys<O, T> = { | ||
[K in keyof O]: O[K] extends T ? K : never; | ||
}[keyof T]; | ||
/** | ||
* Removes properties of type T from O | ||
*/ | ||
export type OmitType<O, T> = Omit<O, TypeKeys<O, T>>; | ||
/** | ||
* Gets all keys with type undefined of T | ||
*/ | ||
type UndefinedKeys<T> = TypeKeys<T, undefined>; | ||
/** | ||
* Removes properties of type undefined from T | ||
*/ | ||
type Defined<T> = Omit<T, UndefinedKeys<T>>; | ||
type Defined<T> = OmitType<T, undefined>; | ||
/** | ||
* All possible iterations for a recursive type | ||
*/ | ||
type MaxRecursiveIterations = 10; | ||
// prettier-ignore | ||
type Iterations = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | ||
/** | ||
* Get nested keys from T in the form of key1.key2... | ||
*/ | ||
type NestedKeys<T extends object> = CoreNestedKeys<T>; | ||
type CoreNestedKeys<T extends object, I extends number = MaxRecursiveIterations> = I extends 0 | ||
? never | ||
: { | ||
[Key in keyof T]: T[Key] extends object | ||
? `${Key}` | `${Key}.${NestedKeys<T[Key], Iterations[I]>}` | ||
: Key; | ||
}[Extract<keyof T, string>]; | ||
/** | ||
* Get nested keys from T in the form of key1.key2... | ||
*/ | ||
type FlattenedNestedKeys<T extends object> = FlattenedCoreNestedKeys<T>; | ||
type FlattenedCoreNestedKeys<T extends object, I extends number = MaxRecursiveIterations> = | ||
I extends 0 | ||
? never | ||
: { | ||
[Key in keyof T]: T[Key] extends object | ||
? `${Key}.${NestedKeys<T[Key], Iterations[I]>}` | ||
: Key; | ||
}[Extract<keyof T, string>]; | ||
/** | ||
* Pick K types from T with keys in the form of key1.key2... | ||
*/ | ||
type DeepPick<T extends object, K extends NestedKeys<T>> = CoreDeepPick<T, K>; | ||
type CoreDeepPick<T extends object, K extends string, I extends number = MaxRecursiveIterations> = | ||
I extends 0 | ||
? never | ||
: K extends `${infer FirstKey}.${infer RestKey}` | ||
? CoreDeepPick<T[FirstKey], RestKey, Iterations[I]> | ||
: T[K]; |
{ | ||
"name": "@peersyst/react-types", | ||
"author": "Peersyst", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "types": "./index.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5884
126