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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -