main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
587 bytes
|
Line | |
---|
1 | /**
|
---|
2 | * Similar to [[Cast]] but with a custom fallback `Catch`. If it fails,
|
---|
3 | * it will enforce `Catch` instead of `A2`.
|
---|
4 | * @param A1 to check against
|
---|
5 | * @param A2 to try/test with
|
---|
6 | * @param Catch to fallback to if the test failed
|
---|
7 | * @returns `A1 | Catch`
|
---|
8 | * @example
|
---|
9 | * ```ts
|
---|
10 | * import {A} from 'ts-toolbelt'
|
---|
11 | *
|
---|
12 | * type test0 = A.Try<'42', string> // '42'
|
---|
13 | * type test1 = A.Try<'42', number> // never
|
---|
14 | * type test1 = A.Try<'42', number, 'tried'> // 'tried'
|
---|
15 | * ```
|
---|
16 | */
|
---|
17 | export declare type Try<A1 extends any, A2 extends any, Catch = never> = A1 extends A2 ? A1 : Catch;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.