type-fest 4.16.0 → 4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "4.16.0",
3
+ "version": "4.17.0",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
package/readme.md CHANGED
@@ -233,10 +233,11 @@ type ShouldBeNever = IfAny<'not any', 'not never', 'never'>;
233
233
  - [`IsNumericLiteral`](source/is-literal.d.ts) - Returns a boolean for whether the given type is a `number` or `bigint` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
234
234
  - [`IsBooleanLiteral`](source/is-literal.d.ts) - Returns a boolean for whether the given type is a `true` or `false` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
235
235
  - [`IsSymbolLiteral`](source/is-literal.d.ts) - Returns a boolean for whether the given type is a `symbol` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
236
- - [`IsAny`](source/is-any.d.ts) - Returns a boolean for whether the given type is `any`. (Conditional version: [`IfAny`](source/if-any.d.ts).)
237
- - [`IsNever`](source/is-never.d.ts) - Returns a boolean for whether the given type is `never`. (Conditional version: [`IfNever`](source/if-never.d.ts).)
238
- - [`IsUnknown`](source/is-unknown.d.ts) - Returns a boolean for whether the given type is `unknown`. (Conditional version: [`IfUnknown`](source/if-unknown.d.ts).)
236
+ - [`IsAny`](source/is-any.d.ts) - Returns a boolean for whether the given type is `any`. (Conditional version: [`IfAny`](source/if-any.d.ts))
237
+ - [`IsNever`](source/is-never.d.ts) - Returns a boolean for whether the given type is `never`. (Conditional version: [`IfNever`](source/if-never.d.ts))
238
+ - [`IsUnknown`](source/is-unknown.d.ts) - Returns a boolean for whether the given type is `unknown`. (Conditional version: [`IfUnknown`](source/if-unknown.d.ts))
239
239
  - [`IsEmptyObject`](source/empty-object.d.ts) - Returns a boolean for whether the type is strictly equal to an empty plain object, the `{}` value. (Conditional version: [`IfEmptyObject`](source/if-empty-object.d.ts))
240
+ - [`IsNull`](source/is-null.d.ts) - Returns a boolean for whether the given type is `null`. (Conditional version: [`IfNull`](source/if-null.d.ts))
240
241
 
241
242
  ### JSON
242
243
 
@@ -0,0 +1,24 @@
1
+ import type {IsNull} from './is-null';
2
+
3
+ /**
4
+ An if-else-like type that resolves depending on whether the given type is `null`.
5
+
6
+ @see {@link IsNull}
7
+
8
+ @example
9
+ ```
10
+ import type {IfNull} from 'type-fest';
11
+
12
+ type ShouldBeTrue = IfNull<null>;
13
+ //=> true
14
+
15
+ type ShouldBeBar = IfNull<'not null', 'foo', 'bar'>;
16
+ //=> 'bar'
17
+ ```
18
+
19
+ @category Type Guard
20
+ @category Utilities
21
+ */
22
+ export type IfNull<T, TypeIfNull = true, TypeIfNotNull = false> = (
23
+ IsNull<T> extends true ? TypeIfNull : TypeIfNotNull
24
+ );
@@ -429,11 +429,6 @@ Returns a boolean for whether the given `boolean` is not `false`.
429
429
  */
430
430
  export type IsNotFalse<T extends boolean> = [T] extends [false] ? false : true;
431
431
 
432
- /**
433
- Returns a boolean for whether the given type is `null`.
434
- */
435
- export type IsNull<T> = [T] extends [null] ? true : false;
436
-
437
432
  /**
438
433
  Disallows any of the given keys.
439
434
  */
@@ -0,0 +1,20 @@
1
+ /**
2
+ Returns a boolean for whether the given type is `null`.
3
+
4
+ @example
5
+ ```
6
+ import type {IsNull} from 'type-fest';
7
+
8
+ type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
9
+
10
+ type Example1 = NonNullFallback<null, string>;
11
+ //=> string
12
+
13
+ type Example2 = NonNullFallback<number, string>;
14
+ //=? number
15
+ ```
16
+
17
+ @category Type Guard
18
+ @category Utilities
19
+ */
20
+ export type IsNull<T> = [T] extends [null] ? true : false;
@@ -1,4 +1,4 @@
1
- import type {IsNull} from './internal';
1
+ import type {IsNull} from './is-null';
2
2
 
3
3
  /**
4
4
  Returns a boolean for whether the given type is `unknown`.
@@ -3,7 +3,7 @@ import type {IsInteger} from './is-integer';
3
3
 
4
4
  export type Numeric = number | bigint;
5
5
 
6
- type Zero = 0 | 0n;
6
+ export type Zero = 0 | 0n;
7
7
 
8
8
  /**
9
9
  Matches the hidden `Infinity` type.