I have a javascript code similar to this:
module.exports = function foo(language, platform, milliseconds) {
// some code
}
This code should be placed in a module ("mymodule") that will be imported through npm.
I want to create the corrisponding .d.ts file.
I have something like this:
declare module 'mymodule' {
export type Language = 'it' | 'es' | 'de';
export type Platform = 'linux' | 'winzoz';
export function foo(language: Language, platform: Platform, milliseconds?: number): void;
}
But of course it did not work. I tried:
-
declare module 'mymodule' { export default function foo(myparams: Types): void; }But this did not work, because I am using
module.exports = function f()and not a default export -
declare module 'mymodule' { function foo(myparams: Types): void; export = foo; }But this did not work, because it says that I should use
esModuleInteropor use an uglyimport foo = require('mymodule'). It does not include the interfaces that I want to export, too.
How can I solve these problems?