Sha256: 6626bbc69c25a92f6d32e6d2f25038f156b4c2380cbf29a420f7084fb1d2f7d7

Contents?: true

Size: 857 Bytes

Versions: 24

Compression:

Stored size: 857 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

24 entries across 24 versions & 1 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.50 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.49 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.48 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.47 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.46 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.45 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.44 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.43 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.42 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.41 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.40 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.39 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.38 node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.32 node_modules/boxen/node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.31 node_modules/boxen/node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.30 node_modules/boxen/node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.29 node_modules/boxen/node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.28 node_modules/boxen/node_modules/type-fest/source/literal-to-primitive.d.ts
immosquare-cleaner-0.1.27 node_modules/boxen/node_modules/type-fest/source/literal-to-primitive.d.ts