← All Exercises
Result Type for Error Handling
intermediatetypescript
Background
Result types provide a functional approach to error handling used in Rust and increasingly in TypeScript.
Problem
Create a Result type that represents either success or failure, enabling explicit error handling without try-catch.
Input
Operations that may fail
Output
Result with success or error value
Sample tests
Sample 1
Input: Result.ok(42)
Expected: {ok: true, value: 42}Your solution
Learning objective
Learn functional error handling and discriminated unions