Socket
Socket
Sign inDemoInstall

type-fest

Package Overview
Dependencies
Maintainers
1
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-fest - npm Package Compare versions

Comparing version 3.7.2 to 3.8.0

source/if-any.d.ts

7

index.d.ts

@@ -58,2 +58,3 @@ // Basic

export type {LiteralToPrimitive} from './source/literal-to-primitive';
export type {LiteralToPrimitiveDeep} from './source/literal-to-primitive-deep';
export type {

@@ -88,2 +89,8 @@ PositiveInfinity,

} from './source/is-literal';
export type {IsAny} from './source/is-any';
export type {IfAny} from './source/if-any';
export type {IsNever} from './source/is-never';
export type {IfNever} from './source/if-never';
export type {IsUnknown} from './source/is-unknown';
export type {IfUnknown} from './source/if-unknown';

@@ -90,0 +97,0 @@ // Template literal types

2

package.json
{
"name": "type-fest",
"version": "3.7.2",
"version": "3.8.0",
"description": "A collection of essential TypeScript types",

@@ -5,0 +5,0 @@ "license": "(MIT OR CC0-1.0)",

@@ -160,2 +160,3 @@ <div align="center">

- [`LiteralToPrimitive`](source/literal-to-primitive.d.ts) - Convert a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) to the [primitive type](source/primitive.d.ts) it belongs to.
- [`LiteralToPrimitiveDeep`](source/literal-to-primitive-deep.d.ts) - Like `LiteralToPrimitive` except it converts literal types inside an object or array deeply.
- [`Stringified`](source/stringified.d.ts) - Create a type with the keys of the given type changed to `string` type.

@@ -177,2 +178,31 @@ - [`IterableElement`](source/iterable-element.d.ts) - Get the element type of an `Iterable`/`AsyncIterable`. For example, an array or a generator.

- [`IsEqual`](source/is-equal.d.ts) - Returns a boolean for whether the two given types are equal.
- [`TaggedUnion`](source/tagged-union.d.ts) - Create a union of types that share a common discriminant property.
### Type Guard
#### `IsType` vs. `IfType`
For every `IsT` type (e.g. `IsAny`), there is an associated `IfT` type that can help simplify conditional types. While the `IsT` types return a `boolean`, the `IfT` types act like an `If`/`Else` - they resolve to the given `TypeIfT` or `TypeIfNotT` depending on whether `IsX` is `true` or not. By default, `IfT` returns a `boolean`:
```ts
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
);
```
#### Usage
```ts
import type {IsAny, IfAny} from 'type-fest';
type ShouldBeTrue = IsAny<any> extends true ? true : false;
//=> true
type ShouldBeFalse = IfAny<'not any'>;
//=> false
type ShouldBeNever = IfAny<'not any', 'not never', 'never'>;
//=> 'never'
```
- [`IsLiteral`](source/is-literal.d.ts) - Returns a boolean for whether the given type is a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).

@@ -183,3 +213,5 @@ - [`IsStringLiteral`](source/is-literal.d.ts) - Returns a boolean for whether the given type is a `string` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).

- [`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).
- [`TaggedUnion`](source/tagged-union.d.ts) - Create a union of types that share a common discriminant property.
- [`IsAny`](source/is-any.d.ts) - Returns a boolean for whether the given type is `any`. (Conditional version: [`IfAny`](source/if-any.d.ts).)
- [`IsNever`](source/is-never.d.ts) - Returns a boolean for whether the given type is `never`. (Conditional version: [`IfNever`](source/if-never.d.ts).)
- [`IsUnknown`](source/is-unknown.d.ts) - Returns a boolean for whether the given type is `unknown`. (Conditional version: [`IfUnknown`](source/if-unknown.d.ts).)

@@ -186,0 +218,0 @@ ### JSON

import type {Primitive} from './primitive';
import type {Simplify} from './simplify';
import type {Trim} from './trim';
import type {IsAny} from './is-any';

@@ -162,19 +163,2 @@ /**

/**
Returns a boolean for whether the the type is `any`.
@link https://stackoverflow.com/a/49928360/1490091
*/
export type IsAny<T> = 0 extends 1 & T ? true : false;
/**
Returns a boolean for whether the the type is `never`.
*/
export type IsNever<T> = [T] extends [never] ? true : false;
/**
Returns a boolean for whether the the type is `unknown`.
*/
export type IsUnknown<T> = IsNever<T> extends false ? T extends unknown ? unknown extends T ? IsAny<T> extends false ? true : false : false : false : false;
/**
For an object T, if it has any properties that are a union with `undefined`, make those into optional properties instead.

@@ -266,1 +250,6 @@

export type IsNotFalse<T extends boolean> = [T] extends [false] ? false : true;
/**
Returns a boolean for whether the given type is `null`.
*/
export type IsNull<T> = [T] extends [null] ? true : false;

@@ -24,2 +24,3 @@ /**

@category Type Guard
@category Utilities

@@ -26,0 +27,0 @@ */

import type {Primitive} from './primitive';
import type {Numeric} from './numeric';
import type {IsNever, IsNotFalse} from './internal';
import type {IsNotFalse} from './internal';
import type {IsNever} from './is-never';

@@ -80,4 +81,4 @@ /**

@category Type Guard
@category Utilities
@category Type Guard
*/

@@ -129,4 +130,4 @@ export type IsStringLiteral<T> = LiteralCheck<T, string>;

@category Type Guard
@category Utilities
@category Type Guard
*/

@@ -170,4 +171,4 @@ export type IsNumericLiteral<T> = LiteralChecks<T, Numeric>;

@category Type Guard
@category Utilities
@category Type Guard
*/

@@ -206,4 +207,4 @@ export type IsBooleanLiteral<T> = LiteralCheck<T, boolean>;

@category Type Guard
@category Utilities
@category Type Guard
*/

@@ -253,5 +254,5 @@ export type IsSymbolLiteral<T> = LiteralCheck<T, symbol>;

@category Type Guard
@category Utilities
@category Type Guard
*/
export type IsLiteral<T extends Primitive> = IsNotFalse<IsLiteralUnion<T>>;
import type {JsonPrimitive, JsonValue} from './basic';
import type {EmptyObject} from './empty-object';
import type {IsAny, UndefinedToOptional} from './internal';
import type {UndefinedToOptional} from './internal';
import type {NegativeInfinity, PositiveInfinity} from './numeric';
import type {TypedArray} from './typed-array';
import type {IsAny} from './is-any';

@@ -7,0 +8,0 @@ // Note: The return value has to be `any` and not `unknown` so it can match `void`.

@@ -1,2 +0,2 @@

import type {IsUnknown} from './internal';
import type {IsUnknown} from './is-unknown';

@@ -3,0 +3,0 @@ /**

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