0.0.9 • Published 3 years ago

in-out-type v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

🧼 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

TypeDescription
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 }
  }
}
0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago