Reputation: 37501
I'm trying to declare an external module which has no existing typings, but am missing something.
The library exports a function which takes no arguments and returns a string.
I'm trying to define it using this in a .d.ts
file:
declare module "cuid" {
export function cuid(): string;
}
In my code, I have import * as cuid from 'cuid';
Yet on the line where I use it, cuid()
I get an error:
error TS2349: Cannot invoke an expression whose type lacks a call signature.
Upvotes: 9
Views: 6506
Reputation: 23772
export function cuid
This syntax matches with your declaration:
import {cuid} from 'cuid';
Here is a good introduction to ES6 modules.
export =
Try:
declare module "cuid" {
function cuid(): string;
export = cuid;
}
... Then use it: import cuid = require('cuid')
.
Upvotes: 16