@alloc/types
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -52,15 +52,22 @@ /** Try to simplify `&` out of an object type */ | ||
/** Intersect a union of objects but merge property types with _unions_ */ | ||
export type ObjectFromUnion<T extends object> = Remap< | ||
{ | ||
[P in keyof Intersect<T>]: T extends infer U | ||
? P extends keyof U | ||
? U[P] | ||
: never | ||
: never | ||
} | ||
> | ||
/** Get the keys of each object type in a given union */ | ||
export type AllKeys<T> = T extends any ? keyof T : never | ||
/** Merge all object types in a given union. Property types are unioned. */ | ||
export type CombineObjects<T> = [AllKeys<T>] extends [infer U] | ||
? { [P in U & string]: CombineProp<T, P> } | ||
: never | ||
/** | ||
* Given a union of object types, find which ones contain the given | ||
* property and merge their types with a union. | ||
*/ | ||
export type CombineProp<T, P extends string> = T extends any | ||
? P extends keyof T | ||
? T[P] | ||
: never | ||
: never | ||
/** Convert a union to an intersection */ | ||
type Intersect<U> = (U extends any | ||
export type Intersect<U> = (U extends any | ||
? (k: U) => void | ||
@@ -67,0 +74,0 @@ : never) extends (k: infer I) => void |
{ | ||
"name": "@alloc/types", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"types": "index.d.ts", | ||
@@ -5,0 +5,0 @@ "files": [ |
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
5278
89