# @mondopower/result-types

> Library to use for result type of typescript functions and helper functions.

Latest version **1.2.2** (published 2025-01-20) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @mondopower/result-types
pnpm add @mondopower/result-types
yarn add @mondopower/result-types
bun add @mondopower/result-types
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2025-01-20 |
| First published | 2021-09-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Maintainers | daryl-miller, mondo-ci |
| Keywords | mondo, projen, result, typescript |

## Links

- npm: https://www.npmjs.com/package/@mondopower/result-types
- Repository: https://github.com/MondoPower/mondo-common-libs
- Homepage: https://github.com/MondoPower/mondo-common-libs#readme
- Issues: https://github.com/MondoPower/mondo-common-libs/issues
- npm.io page: https://npm.io/package/@mondopower/result-types

## Recent versions

- 1.2.2 (latest) — 2025-01-20
- 1.2.1 — 2024-12-03
- 1.1.551 — 2024-03-21
- 1.1.521 — 2024-02-16
- 1.1.519 — 2024-02-14
- 1.1.517 — 2024-02-12
- 1.1.516 — 2024-02-11
- 1.1.515 — 2024-02-10
- 1.1.514 — 2024-02-09
- 1.1.513 — 2024-02-08
- 1.1.512 — 2024-02-06
- 1.1.511 — 2024-02-02
- 1.1.510 — 2024-02-01
- 1.1.509 — 2024-01-31
- 1.1.508 — 2024-01-30
- … 499 more at https://npm.io/package/@mondopower/result-types/versions

## README

# Mondo Result Types

Library to use for result type of typescript functions and helper functions.

## Install

```bash
npm i @mondopower/result-types
```

## Usage

This library consists of two major result types.

### 1) ResultVoid

Used whenever the function will return void in the case of success or failure

```ts
import {raiseFailure, raiseSuccessVoid, ResultVoid} from '@mondopower/result-types'

enum FooErrorType {
  someError= 'someError'
  ...
}

function foo(flag: boolean): ResultVoid<FooErrorType> {
  if (flag)
    return raiseFailure({
      errorType: FooErrorType.someError,
      message: '<my error message>'
    })

  return raiseSuccessVoid()
}

const fooResponse = foo(flag)

if (fooResponse.isErrored)
  // Failure Handling
else
  // success handling
```

### 2) Result


Used whenever the function will return a value/object in the case of success or failure

```ts
import {raiseFailure, raiseSuccess, Result} from '@mondopower/result-types'

enum FooErrorType {
  someError= 'someError'
  ...
}

function foo(flag: boolean): Result<string, FooErrorType> {
  if (flag)
    return raiseFailure({
      errorType: FooErrorType.someError,
      message: '<my error message>'
    })

  return raiseSuccess('success-result')
}

const fooResponse = foo(flag)

if (fooResponse.isErrored)
  // Failure Handling
else {
  // success handling
  const result = fooResponse.data
}
```

## Helpers

This library also includes some helper functions to manage success and failures which all can be found in the [API documentation](https://github.com/MondoPower/mondo-common-libs/docs/packages/mondo-result-types).

---
_Source: https://npm.io/package/@mondopower/result-types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
