in-out-type

0.0.9 • Public • Published

🧼 In/Out Type

TypeScript function I/O utility types

⚙️ Install

npm install in-out-type

⛲ Purpose

Function I/O types eliminate the need to split out arguments and return values to external interfaces.

This removes one level of obscurity from both the function implementation and the function type references.

👻 Types

Type Description
InType<T> Given a function type, get the type of the first argument
OutType<T> Given a function type, get the return type

📽️ Example

Here we create a function that combines two other function's outputs:

import { InType, OutType } from "in-out-type"

async function helloHi({
  hello,
  hi
}: InType<typeof helloWord> &
  InType<typeof hiUniverse>
): Promise<
  OutType<typeof helloWord> &
  OutType<typeof hiUniverse>
> {
  return Object.assign(
    helloWorld({ hello }),
    await hiUniverse({ hi }),
  )
}

function helloWorld(
  { hello }: { hello: boolean }
): { world: boolean } {
  if (hello) {
    return { world: true }
  }
}

async function hiUniverse(
  { hi }: { hi: boolean }
): Promise<{ universe: boolean }> {
  if (hi) {
    return { universe: true }
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i in-out-type

Weekly Downloads

2

Version

0.0.9

License

MIT

Unpacked Size

4.97 kB

Total Files

13

Last publish

Collaborators

  • winton