-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
$special_type.ts
26 lines (24 loc) · 1.08 KB
/
$special_type.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
import type { $Any } from '../any/any.js'
import type { $Never } from '../never/never.js'
import type { $Unknown } from '../unknown/unknown.js'
import type { $BranchOptions } from './branch/$branch.js'
import type { $InputOptions } from './branch/$input_options.js'
import type { $ResolveBranch } from './branch/$resolve_branch.js'
import type { $Else, $SelectionBranch, $Then } from './branch/$selection.js'
import type { $SelectionOptions } from './branch/$selection_options.js'
/**
* 🧰 *type util*
*
* A type utility to handle special types: `any`, `unknown`, and `never`.
*/
export type $SpecialType<T, $O extends $SpecialType.$Options> = 0 extends 1 & T
? $ResolveBranch<T, $O, [$Any, $Then]>
: [T, unknown] extends [unknown, T]
? $ResolveBranch<T, $O, [$Unknown, $Then]>
: [T, never] extends [never, T]
? $ResolveBranch<T, $O, [$Never, $Then]>
: $ResolveBranch<T, $O, [$Else]>
export namespace $SpecialType {
export type $Options = $SelectionOptions & $InputOptions<$Any | $Unknown | $Never>
export type $Branch = $SelectionBranch & $BranchOptions<$Any | $Unknown | $Never>
}