Sha256: e79e530a8216ee171b4aca8fc7b99bd37f5e84555cba57dc3de4cd57580ff21a

Contents?: true

Size: 899 Bytes

Versions: 28

Compression:

Stored size: 899 Bytes

Contents

/**
Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the {@link Primitive | primitive type} it belongs to, or `never` if it's not a primitive.

Use-case: Working with generic types that may be literal types.

@example
```
import type {LiteralToPrimitive} from 'type-fest';

// No overloads needed to get the correct return type
function plus<T extends number | bigint | string>(x: T, y: T): LiteralToPrimitive<T> {
	return x + (y as any);
}

plus('a', 'b'); // string
plus(1, 2); // number
plus(1n, 2n); // bigint
```

@category Type
*/
export type LiteralToPrimitive<T> = T extends number
	? number
	: T extends bigint
		? bigint
		: T extends string
			? string
			: T extends boolean
				? boolean
				: T extends symbol
					? symbol
					: T extends null
						? null
						: T extends undefined
							? undefined
							: never;

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.10 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.9 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.8 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts
clapton-0.0.7 lib/clapton/javascripts/node_modules/type-fest/source/literal-to-primitive.d.ts