Skip to content

Instantly share code, notes, and snippets.

@eesa1980
Last active June 4, 2020 06:50
Show Gist options
  • Save eesa1980/c9cce0adc8b87906be3660b3354034ec to your computer and use it in GitHub Desktop.
Save eesa1980/c9cce0adc8b87906be3660b3354034ec to your computer and use it in GitHub Desktop.
Using a module as a type #typescript #modules #Interface

Say you have the following module:

const SomeModule = () => {
  const add: number = (a: number, b: number) => a + b;
  const subtract: number = (a: number, b: number) => a - b;
  
  return {
    add,
    subtract
  }
}

You can then use the follow module as a type by doing the following:

interface Types {
  someModule : ReturnType<typeof SomeModule>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment