utility-types
Advanced tools
Comparing version 3.10.0 to 3.11.0
@@ -22,2 +22,12 @@ /** | ||
/** | ||
* Nullish | ||
* @desc Type representing [nullish values][https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing] in TypeScript: `null | undefined` | ||
* @example | ||
* type Various = 'a' | 'b' | undefined; | ||
* | ||
* // Expect: "a" | "b" | ||
* Exclude<Various, Nullish>; | ||
*/ | ||
export declare type Nullish = null | undefined; | ||
/** | ||
* Tests for one of the [`Primitive`](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) types using the JavaScript [`typeof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) operator | ||
@@ -55,1 +65,14 @@ * | ||
export declare const isFalsy: (val: unknown) => val is Falsy; | ||
/** | ||
* Tests for Nullish by simply comparing `val` for equality with `null`. | ||
* @example | ||
* const consumer = (param: Nullish | string): string => { | ||
* if (isNullish(param)) { | ||
* // typeof param === Nullish | ||
* return String(param) + ' was Nullish'; | ||
* } | ||
* // typeof param === string | ||
* return param.toString(); | ||
* }; | ||
*/ | ||
export declare const isNullish: (val: unknown) => val is null | undefined; |
@@ -51,2 +51,15 @@ "use strict"; | ||
exports.isFalsy = function (val) { return !val; }; | ||
/** | ||
* Tests for Nullish by simply comparing `val` for equality with `null`. | ||
* @example | ||
* const consumer = (param: Nullish | string): string => { | ||
* if (isNullish(param)) { | ||
* // typeof param === Nullish | ||
* return String(param) + ' was Nullish'; | ||
* } | ||
* // typeof param === string | ||
* return param.toString(); | ||
* }; | ||
*/ | ||
exports.isNullish = function (val) { return val == null; }; | ||
//# sourceMappingURL=aliases-and-guards.js.map |
@@ -9,3 +9,3 @@ /** | ||
export { Falsy, Falsy as Falsey, // deprecated in v3, backward compatibility until v4 | ||
isFalsy, Primitive, isPrimitive, } from './aliases-and-guards'; | ||
isFalsy, Nullish, isNullish, Primitive, isPrimitive, } from './aliases-and-guards'; | ||
export { getReturnOfExpression } from './functional-helpers'; |
@@ -10,2 +10,3 @@ "use strict"; | ||
exports.isFalsy = aliases_and_guards_1.isFalsy; | ||
exports.isNullish = aliases_and_guards_1.isNullish; | ||
exports.isPrimitive = aliases_and_guards_1.isPrimitive; | ||
@@ -12,0 +13,0 @@ // deprecated |
@@ -404,10 +404,10 @@ import { Primitive } from './aliases-and-guards'; | ||
*/ | ||
export declare type DeepPartial<T> = T extends Function ? T : T extends Array<infer U> ? _DeepPartialArray<U> : T extends object ? _DeepPartialObject<T> : T | undefined; | ||
export declare type DeepPartial<T> = { | ||
[P in keyof T]?: _DeepPartial<T[P]>; | ||
}; | ||
/** @private */ | ||
export interface _DeepPartialArray<T> extends Array<DeepPartial<T>> { | ||
export declare type _DeepPartial<T> = T extends Function ? T : T extends Array<infer U> ? _DeepPartialArray<U> : T extends object ? DeepPartial<T> : T | undefined; | ||
/** @private */ | ||
export interface _DeepPartialArray<T> extends Array<_DeepPartial<T>> { | ||
} | ||
/** @private */ | ||
export declare type _DeepPartialObject<T> = { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
}; | ||
/** | ||
@@ -414,0 +414,0 @@ * Brand |
@@ -31,3 +31,3 @@ import { SetComplement, DeepReadonly } from './mapped-types'; | ||
* | ||
* // Expect: Readonly<{ name: string; age?: number | undefined; visible: boolean; }> | ||
* // Expect: Readonly<{ name: string; age: number; visible: boolean; }> | ||
* type ReadOnlyProps = $ReadOnly<Props>; | ||
@@ -97,3 +97,3 @@ */ | ||
* const add = (amount: number) => ({ type: 'ADD' as 'ADD', payload: amount }); | ||
* type AddAction = $Call<typeof returnOfIncrement>; // { type: 'ADD'; payload: number } | ||
* type AddAction = $Call<typeof add>; // { type: 'ADD'; payload: number } | ||
* | ||
@@ -100,0 +100,0 @@ * // Examples migrated from Flow docs |
{ | ||
"name": "utility-types", | ||
"version": "3.10.0", | ||
"version": "3.11.0", | ||
"description": "Utility Types Collection for TypeScript", | ||
@@ -5,0 +5,0 @@ "author": "Piotr Witek <piotrek.witek@gmail.com> (http://piotrwitek.github.io)", |
@@ -91,2 +91,4 @@ <div align="center"> | ||
* [`isFalsy`](#isfalsy) | ||
* [`Nullish`](#nullish) | ||
* [`isNullish`](#isnullish) | ||
@@ -209,2 +211,23 @@ ## Union operators | ||
### `Nullish` | ||
Type representing [nullish values](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing) in TypeScript: `null | undefined` | ||
[⇧ back to top](#table-of-contents) | ||
### `isNullish` | ||
```ts | ||
const consumer = (param: Nullish | string): string => { | ||
if (isNullish(param)) { | ||
// typeof param === Nullish | ||
return String(param) + ' was Nullish'; | ||
} | ||
// typeof param === string | ||
return param.toString(); | ||
}; | ||
``` | ||
[⇧ back to top](#table-of-contents) | ||
### `SetIntersection<A, B>` (same as Extract) | ||
@@ -618,3 +641,3 @@ | ||
// Expect: { name: string; age: number; visible: boolean; other: string; } | ||
// Expect: { name: string; age: string; visible: boolean; other: string; } | ||
type ExtendedProps = Assign<Props, NewProps>; | ||
@@ -958,3 +981,3 @@ ``` | ||
// Expect: Readonly<{ name: string; age?: number | undefined; visible: boolean; }> | ||
// Expect: Readonly<{ name: string; age: number; visible: boolean; }> | ||
type ReadOnlyProps = $ReadOnly<Props>; | ||
@@ -1043,2 +1066,4 @@ ``` | ||
The built-in [`ReturnType`](https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypetype) can be used to accomplish the same goal, although it may have some subtle differences. | ||
**Usage:** | ||
@@ -1051,3 +1076,3 @@ | ||
const add = (amount: number) => ({ type: 'ADD' as 'ADD', payload: amount }); | ||
type AddAction = $Call<typeof returnOfIncrement>; // { type: 'ADD'; payload: number } | ||
type AddAction = $Call<typeof add>; // { type: 'ADD'; payload: number } | ||
@@ -1054,0 +1079,0 @@ // Examples migrated from Flow docs |
Sorry, the diff of this file is not supported yet
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
64326
873
1162