forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
if-any.d.ts
29 lines (21 loc) · 762 Bytes
/
if-any.d.ts
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
import type {IsAny} from './is-any';
/**
An `If`/`Else`-like type that resolves depending on whether the given type is `any`.
If the given type `T` is `any`, the returned type is `TypeIfAny`. Otherwise, the return type is `TypeIfNotAny`. If only `T` is specified, `TypeIfAny` will be `true` and `TypeIfNotAny` will be false.
@see IsAny
@example
```
import type {IsAny, IfAny} from 'type-fest';
type ShouldBeTrue = IsAny<any> extends true ? true : false;
//=> true
type ShouldBeFalse = IfAny<'not any'>;
//=> false
type ShouldBeNever = IfAny<'not any', 'not never', 'never'>;
//=> 'never'
```
@category Type Guard
@category Utilities
*/
export type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
);