-
-
Notifications
You must be signed in to change notification settings - Fork 735
Expand file tree
/
Copy pathis-symbol-literal.d.ts
More file actions
39 lines (30 loc) · 944 Bytes
/
Copy pathis-symbol-literal.d.ts
File metadata and controls
39 lines (30 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type {CollapseLiterals, UnwrapBrand} from './internal/object.d.ts';
import type {IfNotAnyOrNever} from './internal/type.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).
@example
```
import type {IsSymbolLiteral} from 'type-fest';
declare const symbolLiteral1: unique symbol;
declare const symbolLiteral2: unique symbol;
type A = IsSymbolLiteral<typeof symbolLiteral1>;
//=> true
type B = IsSymbolLiteral<symbol>;
//=> false
type C = IsSymbolLiteral<typeof symbolLiteral1 | typeof symbolLiteral2>;
//=> true
```
@category Type Guard
@category Utilities
*/
export type IsSymbolLiteral<T> = IfNotAnyOrNever<T, {
ifNot: _IsSymbolLiteral<CollapseLiterals<UnwrapBrand<T>>>;
ifAny: false;
ifNever: false;
}>;
type _IsSymbolLiteral<T> = T extends symbol
? symbol extends T
? false
: true
: false;
export {};