Reputation: 1373
I'm using the excellent Cleave.js library in my Typescript-based application. Cleave.js is used as follows:
import * as Cleave from 'cleave.js';
new Cleave(element).[whatever]
To aid in development, I'm developing typings for Cleave.js, however, I can't find an pattern in Typescript that allows me to specify the above construct.
When I use export class Cleave { ...} export default Cleave;
In the case above Typescript complains:
TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
When I import Cleave as import Cleave from 'cleave.js'
typescript attempts to find the default
field on the imported object which obviously does not exist.
How can write typings for new-able modules?
Upvotes: 0
Views: 315
Reputation: 15619
This does not work. The import * as X from 'y'
syntax creates a module namespace object. It is meant to be not callable.
You should use the syntax: import Cleave = require('cleave.js')
instead.
For learning how to write typings, check out http://www.typescriptlang.org/docs/handbook/declaration-files/templates.html and related sections in the handbook.
Upvotes: 2