Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

utility-types

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utility-types - npm Package Compare versions

Comparing version 3.4.1 to 3.5.0

4

dist/index.d.ts

@@ -1,3 +0,3 @@

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 { $Call, $Diff, $ElementType, $Keys, $NonMaybeType, $PropertyType, $ReadOnly, $Shape, $Values, Class, } from './utility-types';
export { Assign, Brand, DeepNonNullable, DeepPartial, DeepReadonly, DeepRequired, Diff, Falsey, FunctionKeys, Intersection, NonFunctionKeys, NonUndefined, Omit, Overwrite, Primitive, PromiseType, ReadonlyKeys, SetComplement, SetDifference, SetIntersection, Subtract, SymmetricDifference, Unionize, WritableKeys, } from './mapped-types';
export { getReturnOfExpression } from './functional-helpers';

@@ -0,1 +1,3 @@

export declare type Primitive = number | boolean | string | symbol;
export declare type Falsey = null | undefined | false | 0 | '';
export declare type SetIntersection<A, B> = A extends B ? A : never;

@@ -57,1 +59,20 @@ export declare type SetDifference<A, B> = A extends B ? never : A;

};
declare type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? A : B;
export declare type WritableKeys<T extends object> = {
[P in keyof T]-?: IfEquals<{
[Q in P]: T[P];
}, {
-readonly [Q in P]: T[P];
}, P>;
}[keyof T];
export declare type ReadonlyKeys<T extends object> = {
[P in keyof T]-?: IfEquals<{
[Q in P]: T[P];
}, {
-readonly [Q in P]: T[P];
}, never, P>;
}[keyof T];
export declare type Brand<T, U> = T & {
__brand: U;
};
export {};
{
"name": "utility-types",
"version": "3.4.1",
"version": "3.5.0",
"description": "Utility Types Collection for TypeScript",

@@ -32,3 +32,3 @@ "author": "Piotr Witek <piotrek.witek@gmail.com> (http://piotrwitek.github.io)",

"prepublishOnly": "npm run reinstall && npm run ci-check && npm run build",
"ci-check": "npm run lint && npm run tsc & npm run test"
"ci-check": "npm run lint && npm run tsc && npm run test:update"
},

@@ -41,6 +41,6 @@ "dependencies": {},

"jest": "21.2.1",
"prettier": "1.15.3",
"prettier": "1.16.4",
"ts-jest": "23.10.5",
"tslint": "5.12.1",
"typescript": "3.2.2"
"tslint": "5.15.0",
"typescript": "3.4.1"
},

@@ -47,0 +47,0 @@ "keywords": [

# utility-types
Collection of utility types, complementing TypeScript built-in mapped types and aliases (think "lodash" for static types).
[![Latest Stable Version](https://img.shields.io/npm/v/utility-types.svg)](https://www.npmjs.com/package/utility-types)
[![NPM Downloads](https://img.shields.io/npm/dt/utility-types.svg)](https://www.npmjs.com/package/utility-types)
[![NPM Downloads](https://img.shields.io/npm/dm/utility-types.svg)](https://www.npmjs.com/package/utility-types)
[![Build Status](https://semaphoreci.com/api/v1/piotrekwitek/utility-types/branches/master/shields_badge.svg)](https://semaphoreci.com/piotrekwitek/utility-types)
[![Dependency Status](https://img.shields.io/david/piotrwitek/utility-types.svg)](https://david-dm.org/piotrwitek/utility-types)
[![peerDependency Status](https://img.shields.io/david/peer/piotrwitek/utility-types.svg)](https://david-dm.org/piotrwitek/utility-types#info=devDependencies)
[![License](https://img.shields.io/npm/l/utility-types.svg?style=flat)](https://david-dm.org/piotrwitek/typesafe-actions?type=peer)
## Utility Types Collection for TypeScript
[![NPM Downloads](https://img.shields.io/npm/dm/utility-types.svg)](https://www.npmjs.com/package/utility-types)
[![NPM Downloads](https://img.shields.io/npm/dt/utility-types.svg)](https://www.npmjs.com/package/utility-types)
> #### _Found it useful? Want more updates?_ [**Show your support by giving a :star:**](https://github.com/piotrwitek/utility-types/stargazers)
## TypeScript compatibility notes

@@ -20,7 +22,5 @@ * v1 - minimum TS v2.7.2

The primary goal of this library is to provide a set of proven Utility Types (inspired by [Set Theory](https://en.wikipedia.org/wiki/Set_theory) and functional languages) that should complement existing [TypeScript Mapped Types](https://www.typescriptlang.org/docs/handbook/advanced-types.html).
The primary goal of this library is to provide a set of proven Utility Types that should complement existing [TypeScript Mapped Types](https://www.typescriptlang.org/docs/handbook/advanced-types.html).
The secondary goal is to provide additional utility types compatible with [Flow's Utility Types](https://flow.org/en/docs/types/utilities/).
[Flow](https://flow.org) and [TypeScript](https://typescriptlang.org) have a lot in common. By using this library TypeScript Developers will become more familiar with differences to "Flow" and extend their static-typing toolbelt.
Moreover it can help to migrate between "Flow" and "TypeScript" projects much easier.
The secondary goal is to provide a few additional utility types compatible with [Flow's Utility Types](https://flow.org/en/docs/types/utilities/) helping with gradual migration between "Flow" and "TypeScript" projects.

@@ -35,4 +35,5 @@ ## Goals

* Tested for type correctness with type-testing library `dts-jest`
* Minimal footprint - type-level only, no third-party dependencies
* Thoroughly tested for type correctness with type-testing library `dts-jest`
* Safe with minimal footprint - no third-party dependencies
* No runtime cost - it's type-level only

@@ -46,12 +47,12 @@ ## Installation

## Contributing Guide
If you're planning to contribute please make sure to read the contributing guide: [CONTRIBUTING.md](/CONTRIBUTING.md)
We are open for contributions. If you're planning to contribute please make sure to read the contributing guide: [CONTRIBUTING.md](/CONTRIBUTING.md)
## Sponsor
If you like what we're doing here, you can help us by funding the work on specific issues that you choose by using IssueHunt.io!
**Utility-Types** is an independent open-source project created by people investing their free time for the benefit of our community.
This gives you the power to prioritize our work and support project contributors. Moreover it'll guarantee the project will be updated and maintained in the long run.
If you are using **Utility-Types** please consider donating as this will guarantee the project will be updated and maintained in the long run.
> I keep sponsor anonymity by default but if you'd like your brand to be featured in this repo, please contact me at: piotrek.witek@gmail.com
Issues can be funded by anyone and the money will be transparently distributed to the contributors handling a particular issue.
[![issuehunt-image](https://github.com/BoostIO/issuehunt-materials/blob/master/issuehunt-badge@1x.png?raw=true)](https://issuehunt.io/repos/76400842)
[![Let's fund issues in this repository](https://issuehunt.io/static/embed/issuehunt-button-v1.svg)](https://issuehunt.io/repos/76400842)

@@ -62,21 +63,34 @@ ---

## Operations on sets
## Aliases
* [`SetIntersection<A, B>`](#setintersectiona-b)
* [`SetDifference<A, B>`](#setdifferencea-b)
* [`Primitive`](#primitive)
* [`Falsey`](#falsey)
## Union operators
* [`SetIntersection<A, B>`](#setintersectiona-b-same-as-extract)
* [`SetDifference<A, B>`](#setdifferencea-b-same-as-exclude)
* [`SetComplement<A, A1>`](#setcomplementa-a1)
* [`SymmetricDifference<A, B>`](#symmetricdifferencea-b)
* [`NonNullable<A>`](#nonnullablea) (_\*standard-lib_)
* [`NonUndefined<A>`](#nonundefineda)
* [`Exclude<A, B>`](#excludea-b) (_\*standard-lib_)
* [`Extract<A, B>`](#extracta-b) (_\*standard-lib_)
* [`Exclude<A, B>`](#excludea-b) (_\*built-in_)
* [`Extract<A, B>`](#extracta-b) (_\*built-in_)
* [`NonNullable<T>`](#nonnullablea) (_\*built-in_)
* [`NonUndefined<T>`](#nonundefineda)
## Operations on objects
## Object operators
* [`FunctionKeys<T>`](#functionkeyst)
* [`NonFunctionKeys<T>`](#nonfunctionkeyst)
* [`Pick<T, K>`](#pickt-k) (_\*standard-lib_)
* [`ReadonlyKeys<T>`](#readonlykeyst)
* [`WritableKeys<T>`](#writablekeyst)
* [`Partial<T>`](#partialt) (_\*built-in_)
* [`DeepPartial<T>`](#deeppartialt)
* [`Required<T>`](#requiredt) (_\*built-in_)
* [`DeepRequired<T>`](#deeprequiredt)
* [`Readonly<T>`](#readonlyt) (_\*built-in_)
* [`DeepReadonly<T>`](#deepreadonlyt)
* [`Pick<T, K>`](#pickt-k) (_\*built-in_)
* [`Omit<T, K>`](#omitt-k)
* [`PickByValue<T, ValueType>`](#pickbyvaluet-valuetype)
* [`OmitByValue<T, ValueType>`](#omitbyvaluet-valuetype)
* ~~[`PickByValue<T, ValueType>`](#pickbyvaluet-valuetype)~~ WIP
* ~~[`OmitByValue<T, ValueType>`](#omitbyvaluet-valuetype)~~ WIP
* [`Intersection<T, U>`](#intersectiont-u)

@@ -88,15 +102,9 @@ * [`Diff<T, U>`](#difft-u)

## Mapped Types
## Special operators
* [`Partial<T>`](#partialt) (_\*standard-lib_)
* [`Required<T>`](#requiredt) (_\*standard-lib_)
* [`Readonly<T>`](#readonlyt) (_\*standard-lib_)
* [`ReturnType<T>`](#returntypet) (_\*standard-lib_)
* [`InstanceType<T>`](#instancetypet) (_\*standard-lib_)
* [`ReturnType<T>`](#returntypet) (_\*built-in_)
* [`InstanceType<T>`](#instancetypet) (_\*built-in_)
* [`PromiseType<T>`](#promisetypet)
* [`Unionize<T>`](#unionizet)
* [`PromiseType<T>`](#promisetypet) (replaced deprecated `UnboxPromise<T>`)
* [`DeepReadonly<T>`](#deepreadonlyt)
* [`DeepRequired<T>`](#deeprequiredt)
* [`DeepNonNullable<T>`](#deepnonnullablet)
* [`DeepPartial<T>`](#deeppartialt)
* [`Brand<T, U>`](#brandt-u)

@@ -121,4 +129,15 @@ ## Flow's Utility Types

## Operations on sets
### `Primitive`
Type representing primitive types in TypeScript: `number | boolean | string | symbol`
[⇧ back to top](#table-of-contents)
### `Falsey`
Type representing falsey values in TypeScript: `null | undefined | false | 0 | ''`
> Except `NaN` which cannot be represented as a type literal
[⇧ back to top](#table-of-contents)
### `SetIntersection<A, B>` (same as Extract)

@@ -139,3 +158,3 @@

[⇧ back to top](#operations-on-sets)
[⇧ back to top](#table-of-contents)

@@ -157,3 +176,3 @@ ### `SetDifference<A, B>` (same as Exclude)

[⇧ back to top](#operations-on-sets)
[⇧ back to top](#table-of-contents)

@@ -173,3 +192,3 @@ ### `SetComplement<A, A1>`

[⇧ back to top](#operations-on-sets)
[⇧ back to top](#table-of-contents)

@@ -189,3 +208,3 @@ ### `SymmetricDifference<A, B>`

[⇧ back to top](#operations-on-sets)
[⇧ back to top](#table-of-contents)

@@ -196,3 +215,3 @@ ### `NonNullable<A>`

[⇧ back to top](#operations-on-sets)
[⇧ back to top](#table-of-contents)

@@ -203,3 +222,3 @@ ### `NonUndefined<A>`

[⇧ back to top](#operations-on-sets)
[⇧ back to top](#table-of-contents)

@@ -210,3 +229,3 @@ ### `Exclude<A, B>`

[⇧ back to top](#operations-on-sets)
[⇧ back to top](#table-of-contents)

@@ -217,6 +236,4 @@ ### `Extract<A, B>`

[⇧ back to top](#operations-on-sets)
[⇧ back to top](#table-of-contents)
---
## Operations on objects

@@ -238,3 +255,3 @@

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -255,3 +272,3 @@ ### `NonFunctionKeys<T>`

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -262,3 +279,3 @@ ### `Pick<T, K>`

> _(part of standard-lib)_
> _(part of built-in)_

@@ -274,3 +291,3 @@ **Usage:**

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -292,3 +309,3 @@ ### `Omit<T, K>`

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -311,3 +328,3 @@ ### `PickByValue<T, ValueType>`

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -330,3 +347,3 @@ ### `OmitByValue<T, ValueType>`

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -349,3 +366,3 @@ ### `Intersection<T, U>`

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -368,3 +385,3 @@ ### `Diff<T, U>`

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -387,3 +404,3 @@ ### `Subtract<T, T1>`

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -406,3 +423,3 @@ ### `Overwrite<T, U>`

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)

@@ -425,8 +442,36 @@ ### `Assign<T, U>`

[⇧ back to top](#operations-on-objects)
[⇧ back to top](#table-of-contents)
---
### `ReadonlyKeys<T>`
## Mapped Types
Get union type of keys that are readonly in object type `T`
**Usage:**
```ts
import { ReadonlyKeys } from 'utility-types';
type Props = { readonly foo: string; bar: number };
type ReadonlyProps = ReadonlyKeys<Props>;
// Expect: "foo"
```
[⇧ back to top](#table-of-contents)
### `WritableKeys<T>`
Get union type of keys that are writable (not readonly) in object type `T`
**Usage:**
```ts
import { WritableKeys } from 'utility-types';
type Props = { readonly foo: string; bar: number };
type WritableProps = WritableKeys<Props>;
// Expect: "bar"
```
[⇧ back to top](#table-of-contents)
### `Partial<T>`

@@ -436,3 +481,3 @@

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)

@@ -443,3 +488,3 @@ ### `Required<T>`

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)

@@ -450,3 +495,3 @@ ### `Readonly<T>`

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)

@@ -457,3 +502,3 @@ ### `ReturnType<T>`

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)

@@ -464,3 +509,3 @@ ### `InstanceType<T>`

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)

@@ -482,3 +527,3 @@ ### `Unionize<T>`

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)

@@ -498,3 +543,3 @@ ### `PromiseType<T>`

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)

@@ -527,6 +572,4 @@ ### `DeepReadonly<T>`

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)
---
### `DeepRequired<T>`

@@ -558,6 +601,4 @@

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)
---
### `DeepNonNullable<T>`

@@ -589,6 +630,4 @@

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)
---
### `DeepPartial<T>`

@@ -620,4 +659,30 @@

[⇧ back to top](#mapped-types)
[⇧ back to top](#table-of-contents)
### `Brand<T, U>`
Define nominal type of `U` based on type of `T`.
**Usage:**
```ts
import { Brand } from 'utility-types';
type USD = Brand<number, "USD">
type EUR = Brand<number, "EUR">
const tax = 5 as USD;
const usd = 10 as USD;
const eur = 10 as EUR;
function gross(net: USD): USD {
return (net + tax) as USD;
}
gross(usd); // ok
gross(eur); // Type '"EUR"' is not assignable to type '"USD"'.
```
[⇧ back to top](#flows-utility-types)
---

@@ -828,3 +893,2 @@

class Store {}

@@ -831,0 +895,0 @@ function makeStore(storeClass: Class<Store>): Store {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc