utility-types
Advanced tools
Comparing version 3.2.1 to 3.4.1
@@ -1,3 +0,3 @@ | ||
export { $Call, $Keys, $Values, $ReadOnly, $Diff, $PropertyType, $ElementType, $Shape, $NonMaybeType, } from './utility-types'; | ||
export { Assign, DeepReadonly, DeepRequired, DeepNonNullable, Diff, FunctionKeys, Intersection, NonFunctionKeys, NonUndefined, Omit, Overwrite, PromiseType, SetComplement, SetDifference, SetIntersection, Subtract, SymmetricDifference, Unionize, } from './mapped-types'; | ||
export { $Call, $Keys, $Values, $ReadOnly, $Diff, $PropertyType, $ElementType, $Shape, $NonMaybeType, Class, } from './utility-types'; | ||
export { Assign, DeepReadonly, DeepRequired, DeepNonNullable, DeepPartial, Diff, FunctionKeys, Intersection, NonFunctionKeys, NonUndefined, Omit, Overwrite, PromiseType, SetComplement, SetDifference, SetIntersection, Subtract, SymmetricDifference, Unionize, } from './mapped-types'; | ||
export { getReturnOfExpression } from './functional-helpers'; |
@@ -13,2 +13,8 @@ export declare type SetIntersection<A, B> = A extends B ? A : never; | ||
export declare type Omit<T extends object, K extends keyof T> = T extends any ? Pick<T, SetDifference<keyof T, K>> : never; | ||
export declare type PickByValue<T, ValueType> = Pick<T, { | ||
[Key in keyof T]: T[Key] extends ValueType ? Key : never; | ||
}[keyof T]>; | ||
export declare type OmitByValue<T, ValueType> = Pick<T, { | ||
[Key in keyof T]: T[Key] extends ValueType ? never : Key; | ||
}[keyof T]>; | ||
export declare type Intersection<T extends object, U extends object> = T extends any ? Pick<T, SetIntersection<keyof T, keyof U>> : never; | ||
@@ -46,1 +52,7 @@ export declare type Diff<T extends object, U extends object> = Pick<T, SetDifference<keyof T, keyof U>>; | ||
}; | ||
export declare type DeepPartial<T> = T extends Function ? T : T extends Array<infer U> ? _DeepPartialArray<U> : T extends object ? _DeepPartialObject<T> : T | undefined; | ||
export interface _DeepPartialArray<T> extends Array<DeepPartial<T>> { | ||
} | ||
export declare type _DeepPartialObject<T> = { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
}; |
@@ -13,1 +13,2 @@ import { SetComplement, DeepReadonly } from './mapped-types'; | ||
export declare type $NonMaybeType<T> = NonNullable<T>; | ||
export declare type Class<T> = new (...args: any[]) => T; |
{ | ||
"name": "utility-types", | ||
"version": "3.2.1", | ||
"version": "3.4.1", | ||
"description": "Utility Types Collection for TypeScript", | ||
@@ -38,7 +38,7 @@ "author": "Piotr Witek <piotrek.witek@gmail.com> (http://piotrwitek.github.io)", | ||
"dts-jest": "22.0.4", | ||
"husky": "1.3.0", | ||
"husky": "1.3.1", | ||
"jest": "21.2.1", | ||
"prettier": "1.15.3", | ||
"ts-jest": "23.10.5", | ||
"tslint": "5.12.0", | ||
"tslint": "5.12.1", | ||
"typescript": "3.2.2" | ||
@@ -45,0 +45,0 @@ }, |
@@ -76,2 +76,4 @@ # utility-types | ||
* [`Omit<T, K>`](#omitt-k) | ||
* [`PickByValue<T, ValueType>`](#pickbyvaluet-valuetype) | ||
* [`OmitByValue<T, ValueType>`](#omitbyvaluet-valuetype) | ||
* [`Intersection<T, U>`](#intersectiont-u) | ||
@@ -95,2 +97,3 @@ * [`Diff<T, U>`](#difft-u) | ||
* [`DeepNonNullable<T>`](#deepnonnullablet) | ||
* [`DeepPartial<T>`](#deeppartialt) | ||
@@ -108,2 +111,3 @@ ## Flow's Utility Types | ||
* [`$NonMaybeType<T>`](#nonmaybetypet) | ||
* [`Class<T>`](#classt) | ||
@@ -275,2 +279,38 @@ ## Deprecated API (use at own risk) | ||
### `PickByValue<T, ValueType>` | ||
From `T` pick a set of properties with value type of `ValueType`. | ||
Credit: [Piotr Lewandowski](https://medium.com/dailyjs/typescript-create-a-condition-based-subset-types-9d902cea5b8c) | ||
**Usage:** | ||
```ts | ||
import { PickByValue } from 'utility-types'; | ||
type Props = { name: string; age: number; visible: boolean }; | ||
type RequiredProps = PickByValue<Props, string | number>; | ||
// Expect: { name: string; age: number } | ||
``` | ||
[⇧ back to top](#operations-on-objects) | ||
### `OmitByValue<T, ValueType>` | ||
From `T` remove a set of properties with value type of `ValueType`. | ||
Credit: [Piotr Lewandowski](https://medium.com/dailyjs/typescript-create-a-condition-based-subset-types-9d902cea5b8c) | ||
**Usage:** | ||
```ts | ||
import { OmitByValue } from 'utility-types'; | ||
type Props = { name: string; age: number; visible: boolean }; | ||
type RequiredProps = OmitByValue<Props, string | number>; | ||
// Expect: { visible: boolean } | ||
``` | ||
[⇧ back to top](#operations-on-objects) | ||
### `Intersection<T, U>` | ||
@@ -522,2 +562,32 @@ | ||
### `DeepPartial<T>` | ||
Partial that works for deeply nested structures | ||
**Usage:** | ||
```ts | ||
import { DeepPartial } from 'utility-types'; | ||
type NestedProps = { | ||
first: { | ||
second: { | ||
name: string; | ||
}; | ||
}; | ||
}; | ||
type PartialNestedProps = DeepPartial<NestedProps>; | ||
// Expect: { | ||
// first?: { | ||
// second?: { | ||
// name?: string; | ||
// }; | ||
// }; | ||
// } | ||
``` | ||
[⇧ back to top](#mapped-types) | ||
--- | ||
## Flow's Utility Types | ||
@@ -715,2 +785,22 @@ | ||
### `Class<T>` | ||
Given a type T representing instances of a class C, the type Class<T> is the type of the class C | ||
https://flow.org/en/docs/types/utilities/#toc-class | ||
\* Differs from original Flow's util - implements only constructor part and won't include any static members. Additionally classes in Typescript are not treated as nominal | ||
**Usage:** | ||
```ts | ||
import { Class } from 'utility-types'; | ||
class Store {} | ||
function makeStore(storeClass: Class<Store>): Store { | ||
return new storeClass(); | ||
} | ||
``` | ||
[⇧ back to top](#flows-utility-types) | ||
--- | ||
@@ -717,0 +807,0 @@ |
Sorry, the diff of this file is not supported yet
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
28111
88
805