Skip to main content
Module

x/ts_toolbelt_unofficial/mod.ts>Any.Try

👷 TypeScript's largest type utility library, now on Deno
Latest
type alias Any.Try
import { type Any } from "https://deno.land/x/ts_toolbelt_unofficial@1.1.0/mod.ts";
const { Try } = Any;

Similar to [[Cast]] but with a custom fallback Catch. If it fails, it will enforce Catch instead of A2.

Examples

Example 1

import {A} from 'ts-toolbelt.ts'

type test0 = A.Try<'42', string>          // '42'
type test1 = A.Try<'42', number>          // never
type test1 = A.Try<'42', number, 'tried'> // 'tried'

Type Parameters

A1 extends any
A2 extends any
optional
Catch = never
definition: A1 extends A2 ? A1 : Catch