1

U function in a Node module I'm trying to describe in .d.ts has two aliases, config() and load() (see the source). The function can be described like this in dotenv/index.d.ts:

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

How do I also export it under the other alias, load()?

1 Answer 1

5

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: https://www.typescriptlang.org/docs/handbook/advanced-types.html (the section on type guards and differentiating types). Just something cool I only recently came across.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I actually think the type is Object | false. I've submitted a PR to DefinitelyTyped with the fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.