# returnof

> TypeScript typeof function return helper

Latest version **1.1.1** (published 2017-03-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install returnof
pnpm add returnof
yarn add returnof
bun add returnof
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2017-03-31 |
| First published | 2017-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Chris Feijoo |
| Maintainers | kube |

## Links

- npm: https://www.npmjs.com/package/returnof
- Repository: https://github.com/kube/returnof
- Homepage: https://github.com/kube/returnof#readme
- Issues: https://github.com/kube/returnof/issues
- npm.io page: https://npm.io/package/returnof

## Recent versions

- 1.1.1 (latest) — 2017-03-31
- 1.1.0 — 2017-03-30
- 1.0.0 — 2017-02-05

## README

returnof
========

A workaround to get the return type of a function in TypeScript.

Install
-------

```sh
npm install returnof
```


Function return type
--------------------

At the moment TypeScript does not allow to get the **return type of a function**.

```ts
const hello = () => ({ hello: 'World' })

type helloReturnType = typeof hello() // ERROR
```

`returnof` allows you to get it, at the cost of (a little) more verbosity.

```ts
import returnof from 'returnof'

const hello = () => ({ hello: 'World' })

const helloReturnValue = returnof(hello)
type helloReturnType = typeof helloReturnValue // { hello: string }
```

At runtime, `helloReturnValue` will be `null`.


Overloaded functions
--------------------

If your function is overloaded and there is an ambiguity on which one you're trying to get the return type, you can pass additional arguments:

```ts
declare function hello(): void;
declare function hello(a: number): number;

const helloReturnValue = returnof(hello)
type helloReturnType = typeof helloReturnValue // void

const helloReturnValue = returnof(hello, 42)
type helloReturnType = typeof helloReturnValue // number
```

If there's no ambiguity, you **do not need** to pass additional arguments:

```ts
declare function hello(a: number): number;

const helloReturnValue = returnof(hello)
type helloReturnType = typeof helloReturnValue // number
```

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