Export multiple functions in typescript package

Viewed 9383

I'm writing a npm package in Typescript which implements several functions.

At the moment, I'm importing all the functions in a file index.ts and re-export them immediately:

import { functionA, functionB } from "./file1";
import { functionC, functionD } from "./file2";
export {
  function A,
  function B,
  function C,
  function D,  
}

I can use them in other projects using import { functionA } from "package";

However I'd like to export these functions so that I can use the package like this in another project (without using a class):

import _ from "package"
const foo = _.functionA(...);
const bar = _.functionB(...);

This is similar to the implementation of Lodash. I've searched in many places but exporting stuff in typescript is quite confusing (for instance, index.d.ts in lodash has two exports for _ and some declare const, declare namespace stuff...)

2 Answers

Export the default object with those properties:

const _ = {
  functionA,
  functionB
}

export default _;
Related