-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
312 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,72 @@ | ||
import type { $SelectionOptions, $SelectionPredicate } from '../type_plus/branch/selection.js' | ||
import type { $SelectionOptions } from '../type_plus/branch/selection.js' | ||
import type { $ResolveOptions } from '../type_plus/resolve_options.js' | ||
import type { $NotNever } from './never.js' | ||
|
||
/** | ||
* 🎭 *predicate* | ||
* 🔢 *customize* | ||
* | ||
* Validate if `T` is `never`. | ||
* | ||
* @example | ||
* ```ts | ||
* type R = IsNever<never> // true | ||
* | ||
* type R = IsNever<1> // false | ||
* ``` | ||
* | ||
* 🔢 *customize*: branching | ||
* 🔢 *customize* | ||
* | ||
* Filter to ensure `T` is `never`, otherwise returns `$NotNever`. | ||
* | ||
* Filter normally returns `never` in the `$else` clause. | ||
* But since we are checking for `never` here, | ||
* we have to return `$NotNever` instead. | ||
* | ||
* @example | ||
* ```ts | ||
* type R = IsNever<never, { selection: 'filter' }> // never | ||
* | ||
* type R = IsNever<1, { selection: 'filter' }> // $NotNever | ||
* ``` | ||
* | ||
* 🔢 *customize* | ||
* | ||
* Filter to ensure `T` is `never`, otherwise returns `unknown`. | ||
* | ||
* @example | ||
* ```ts | ||
* type R = IsNever<1, { selection: 'filter-unknown' }> // unknown | ||
* ``` | ||
* | ||
* 🔢 *customize* | ||
* | ||
* Use unique branch identifiers to allow precise processing of the result. | ||
* | ||
* @example | ||
* ```ts | ||
* type R = IsNever<never, $SelectionBranch> // $Then | ||
* type R = IsNever<1, $SelectionBranch> // $Else | ||
* ``` | ||
*/ | ||
export type IsNever< | ||
T, | ||
$O extends $SelectionOptions = $SelectionPredicate | ||
$O extends IsNever.$Options = {} | ||
> = [T, never] extends [never, T] | ||
? $ResolveOptions<[$O['$then'], true]> | ||
: $ResolveOptions<[$O['$else'], false]> | ||
? $ResolveOptions<[$O['$then'], $O['selection'] extends 'filter' | 'filter-unknown' ? T : true]> | ||
: $ResolveOptions<[$O['$else'], $O['selection'] extends 'filter' | ||
? $NotNever | ||
: $O['selection'] extends 'filter-unknown' ? unknown : false]> | ||
|
||
|
||
export namespace IsNever { | ||
export type $Options = Omit<$SelectionOptions, 'selection'> & { | ||
/** | ||
* On top of `selection` values from `$SelectionOptions`, | ||
* | ||
* it also support: | ||
* | ||
* `filter-unknown` which returns `unknown` when `T` is `never` | ||
*/ | ||
selection?: 'predicate' | 'filter' | 'filter-unknown' | undefined | ||
} | ||
} |
Oops, something went wrong.