Borek Borek - 1 year ago 143
TypeScript Question

TypeScript: function alias in .d.ts

U function in a Node module I'm trying to describe in

has two aliases,
(see the source). The function can be described like this in

export function config(options?: dotenvOptions): Object;

How do I also export it under the other alias,

Answer Source

You can declare a type:

declare type ConstructorMethod = (options?: dotenvOptions) => Object;

(name can be better)

Then export the two methods as the same type:

export const config: ConstructorMethod;
export const load: ConstructorMethod;

P.S. Looks like the return type is actually object | boolean. Union types might be annoying, but I thought I might point you in this direction in case you become annoyed in future: (the section on type guards and differentiating types). Just something cool I only recently came across.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download