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 +1 -1
- package/readme.md +4 -3
- package/source/if-null.d.ts +24 -0
- package/source/internal.d.ts +0 -5
- package/source/is-null.d.ts +20 -0
- package/source/is-unknown.d.ts +1 -1
- package/source/numeric.d.ts +1 -1
package/package.json
CHANGED
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
|
+
);
|
package/source/internal.d.ts
CHANGED
|
@@ -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;
|
package/source/is-unknown.d.ts
CHANGED