0

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?

1

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

And how should I write the typings, which is my ultimate question?
Updated with link to that :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.