node.js - Exception with type definition for random-string module -


i trying write .d.ts random-string.

i have code:

declare module "random-string" {     export function randomstring(opts?: object): string; } 

i able import module no problem with:

import randomstring = require('random-string'); 

and invoke:

console.log(randomstring); // --> [function: randomstring] 

however, doesn't work or without argument:

console.log(randomstring({length: 10}); console.log(randomstring()); 

i error tsc:

error ts2088: cannot invoke expression type lacks call signature.

i looked in source random-string , found code method trying interface with:

module.exports = function randomstring(opts) {    // implementation... }; 

i managed write .d.ts cson module, no problem, exporting 'class' rather function directly. significant?

your declaration says there module named random-string function named randomstring within it...

so usage should be:

console.log(randomstring.randomstring({ length: 10 })); console.log(randomstring.randomstring()); 

if module supply function directly, should adjust definition same:

declare module "random-string" {     function randomstring(opts?: object): string;      export = randomstring; } 

this allow call in question.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -