Functional way of throwing errors in JS/TS
npm install panic-fn


Functional way of throwing errors in JS/TS
Have you ever tried to do this?
``ts`
callback(() => throw new Error("Not implemented"));
// or this
doStuff(value ?? throw new Error("No value provided"));
But got Uncaught SyntaxError: Unexpected token 'throw'.
With panic-fn it works as expected.
`ts`
callback(() => panic("Not implemented"));
// or this
doStuff(value ?? panic("No value provided"));
You can also throw custom errors:
`tsUnexpected token 'throw'
panic(new SyntaxError());`
`bash`
npm i panic-fn
`ts`
import { panic } from "panic-fn";
`ts``
import { panic } from "https://deno.land/x/panic_fn/mod.ts";
This module was created using denoland/dnt.
Source is written in Deno and compiles to both Node.js CJS and ESM.