Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/error/index.ts>fromObject

A JavaScript extension package for building strong and modern applications.
Latest
function fromObject
import { fromObject } from "https://deno.land/x/ayonli_jsext@v0.9.72/error/index.ts";

Reverses a plain object to a specific error type.

Examples

Example 1

import { fromObject } from "@ayonli/jsext/error";

const obj = {
    "@@type": "Error",
    name: "Error",
    message: "Something went wrong.",
    stack: "Error: Something went wrong.\n    at <anonymous>:1:13"
};

const err = fromObject(obj);
console.log(err);
// Error: Something went wrong.
//     at <anonymous>:1:13

Type Parameters

T extends { name: "Error"; }

Returns

Error

Type Parameters

T extends { name: "EvalError"; }

Returns

EvalError

Type Parameters

T extends { name: "RangeError"; }

Returns

RangeError

Type Parameters

T extends { name: "ReferenceError"; }

Returns

ReferenceError

Type Parameters

T extends { name: "SyntaxError"; }

Returns

SyntaxError

Type Parameters

T extends { name: "TypeError"; }

Returns

TypeError

Type Parameters

T extends { name: "URIError"; }

Returns

URIError

Type Parameters

T extends { name: "Exception"; }

Type Parameters

T extends Error

Parameters

obj: { [x: string | symbol]: any; }
optional
ctor: Constructor<Error>

Returns

T | null