frontend/.pnpm-store/v3/files/f3/bbd349c65c2bf8e6f4723a5d5fff23327fe58ab73b7c4c58706cb76877ec7099e11e695d1171919d8c3a76ce7aaf451c9db020b2710fd64dde6324979f406c

37 lines
899 B
Plaintext

/**
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;