error.ts

view source

Declarations
#

3 declarations

to_error_message
#

error.ts view source

(value: unknown, fallback?: string | undefined): string import {to_error_message} from '@fuzdev/fuz_util/error.js';

Extract a human-readable message from an unknown thrown value. Returns value.message when value is an Error, otherwise fallback (defaulting to String(value)).

value

type unknown

fallback?

type string | undefined
optional

returns

string

unreachable
#

error.ts view source

(value: never, message?: string | undefined): asserts value is never import {unreachable} from '@fuzdev/fuz_util/error.js';

Beyond terseness, this is useful because throw is not an expression, and therefore can't be used in places like Svelte markup without a workaround, at least until this proposal is accepted and widely available: https://github.com/tc39/proposal-throw-expressions

value

type never

message?

type string | undefined
optional

returns

void

UnreachableError
#

error.ts view source

import {UnreachableError} from '@fuzdev/fuz_util/error.js';

Error for asserting unreachable code paths in TypeScript. Useful for exhaustive matching.

inheritance

extends: Error

constructor

type new (value: never, message?: string, options?: ErrorOptions | undefined): UnreachableError

value

type never

message

type string
default `Unreachable case: ${value}`

options?

type ErrorOptions | undefined
optional

Imported by
#