Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungWhy Claude Code keeps writing shell commands that fail on your Mac(20.09.2026 um 21:06 Uhr)
Sichere Programmierungllms.txt v2: What the Spec Says, and What 137,000 Domains Show(20.09.2026 um 21:17 Uhr)
Sicherheitslücken (CVE)NiceTryGPT: Less pattern matching. More actual hacking.(20.09.2026 um 21:19 Uhr)
IT Security VideoActivities BoF (kde2026)(20.09.2026 um 00:00 Uhr)
IT Security Toolsirdoc-app(20.09.2026 um 20:33 Uhr)
Sichere ProgrammierungWhy Claude Code keeps writing shell commands that fail on your Mac(20.09.2026 um 21:06 Uhr)
Sichere Programmierungllms.txt v2: What the Spec Says, and What 137,000 Domains Show(20.09.2026 um 21:17 Uhr)
Sicherheitslücken (CVE)NiceTryGPT: Less pattern matching. More actual hacking.(20.09.2026 um 21:19 Uhr)
IT Security VideoActivities BoF (kde2026)(20.09.2026 um 00:00 Uhr)
IT Security Toolsirdoc-app(20.09.2026 um 20:33 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Bringing Rust & Go-Inspired Functional Error Handling to TypeScript

Reagiere als Erste:r — dein Feedback zählt!

Functional programming isn’t just for Haskell or Scala anymore — with TypeScript’s evolving type system, we can now model powerful concepts like safe error handling, optional values, and composable results in a clean, type-safe way.

ts-fp-utils is a small but expressive functional programming library for TypeScript that brings together the best of Rust’s Result and Option with Go’s error semantics.

👉 NPM Package:

npm install ts-fp-utils

💡 Why Another FP Library?

Most TypeScript codebases handle errors using plain try/catch blocks, which can get messy and unpredictable — especially in async-heavy systems or service layers.

This library was built to solve three real-world problems:

  1. Make error handling composable and predictable
  2. Avoid null checks everywhere with an expressive Option type
  3. Introduce domain-specific failures inspired by Go and DDD

In short: make failure a first-class citizen of your TypeScript code.

⚙️ The Core Modules

File Role
pair.ts Simple immutable key–value pair
option.ts Optional value wrapper (Rust’s Option)
result.ts Success/error container (Rust’s Result)
failure.ts Base error abstraction (Go’s error)
failures.ts Helper methods for working with Failure
ApiFailure.ts, EntityNotFound.ts, etc. Domain-level exception classes

🧠 Option — Safe Optional Values

Rust’s Option<T> inspired our implementation.
It lets you express “value or none” semantics clearly.

import { Option } from "ts-fp-utils";

const userId = Option.orUndefinedOrNullable(null);

console.log(userId.isEmpty()); // true

const fallback = userId.getOrElse("guest");
console.log(fallback); // guest

const name = Option.ok("John Doe")
  .map(n => n.toUpperCase())
  .get();

console.log(name); // JOHN DOE

Async? No problem 👇

const asyncOpt = await Option.of(async () => "Hello Async");
console.log(asyncOpt.get()); // Hello Async

🧩 Composing with Result

The Result<T, E> type (inspired by Rust) ties it all together — representing success or failure outcomes without throwing exceptions.

import { Result } from "ts-fp-utils";

function divide(a: number, b: number): Result<number, Failure> {
  if (b === 0) return Result.err(new IllegalArgument("Division by zero"));
  return Result.ok(a / b);
}

const result = divide(10, 0);
if (result.isErr()) console.error(result.unwrapErr().message);

💥 Failure — When Things Go Wrong

Inspired by Go’s error and Kotlin’s Result.Failure, this class makes failures explicitly representable and composable.

import { Failure } from "ts-fp-utils";

try {
  const op = Failure.of(() => {
    throw new Error("Network timeout!");
  });
  op.ifPresent(f => console.error("Failure occurred:", f.message));
} catch (err) {
  console.error("Unexpected exception:", err);
}

Wrapping causes

const wrapped = Failure.wrap("Outer context", new TypeError("Invalid response"));
console.log(wrapped.toString());
// Failure{message='Outer context', cause=TypeError('Invalid response')}

🧰 Failure Helpers

Helper methods to make common failure patterns easier.

import {
  emptyFailure,
  failureWithMessage,
  wrapFailure,
  wrapExistingFailure
} from "ts-fp-utils";

const fail = failureWithMessage("Validation failed");
console.log(fail.isPresent()); // true

const wrapped = wrapFailure("Database insert failed", new Error("Unique constraint violated"));
console.log(wrapped.message); // Database insert failed

🚨 Domain-Specific Failures

You can define meaningful, domain-aware failures — no more vague throw new Error().

import {
  EntityNotFound,
  EntityAlreadyExists,
  AuthFailure,
  OperationNotAllowed
} from "ts-fp-utils";

function findUser(id: string) {
  if (!id) throw new AuthFailure("User not authenticated.");
  throw new EntityNotFound(`User with ID ${id} not found.`);
}

try {
  findUser("123");
} catch (err) {
  if (err instanceof EntityNotFound) console.error("Not Found:", err.message);
}

Built-in failure types include:

  • ApiFailure
  • AuthFailure
  • EntityAlreadyExists
  • EntityNotFound
  • EntityValidationFailed
  • IllegalArgument
  • IllegalState
  • InternalFailure
  • InvalidRequest
  • OperationNotAllowed

Each extends the base Failure class and adds clear semantic meaning to your application’s flow.

🧱 Built for Real Systems

This library was designed for use in backend applications, domain-driven systems, and API layers where:

  • You need robust error propagation
  • You prefer explicit control flow over exceptions
  • You want Go-like simplicity with Rust-like safety

🚀 Try It Out

npm install ts-fp-utils

Then start composing safe, expressive TypeScript today.
No more surprise undefined, no more hidden exceptions.

💬 Final Thoughts

By combining Rust’s Result & Option patterns with Go’s pragmatic error philosophy, we can bring clarity and safety to everyday TypeScript.

If you’re tired of fighting try/catch, or your codebase is full of null guards — give this library a spin.

GitHub: github.com/veerakumarak/ts-fp-utils
NPM: npmjs.com/package/ts-fp-utils

🧡 Happy functional programming in TypeScript!

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Bringing Rust & Go-Inspired Functional Error Handling to TypeScript

Thematisch verwandte Begriffe: Bringing, Rust, GoInspired, Functional · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-93956 | A flaw has been found in olivier-ls PHP-FTS up to 1.1.2. Affected by thi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick