0

I use a node module that's not found by typings and doesn't exist in definelytyped.

the basic use of the module is:

import * as someFunc from 'some-module';

someFunc("some string");

As you can see, this module exports a function as its default. I haven't figured out how to write the declaration file for it.

This is the best I managed to do:

declare module 'some-module' {
    export default function someFunc(someArg: string): void;
}

BTW it does work JavaScriptly. It's only the TypeScript bothers me.

Any ideas how to solve that?

1 Answer 1

3

declaration:

declare module 'some-module' {
  var exportFunction : (arg: string) => void;
  export = exportFunction;
}

usage:

import * as someFunc from "some-module";
someFunc(a)';

Is how this can be done.

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

2 Comments

The opening parenthesis (in var exportFunction = (arg: string) => void;) is marked with red, saying: TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type.
fixed. Should be declaration of type instead of an assignement, change = to :

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.