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.
3
4
Use-case: Working with generic types that may be literal types.
5
6
@example
7
```
8
import type {LiteralToPrimitive} from 'type-fest';
9
10
// No overloads needed to get the correct return type
11
function plus<T extends number | bigint | string>(x: T, y: T): LiteralToPrimitive<T> {
12
return x + (y as any);
13
}
14
15
plus('a', 'b'); // string
16
plus(1, 2); // number
17
plus(1n, 2n); // bigint
18
```
19
20
@category Type
21
*/
22
exporttype LiteralToPrimitive<T> = T extendsnumber