1

I am trying to use the big.js library, whose definition is here.

Now, this line works:

const CONSTANT_1 = new Big(0);

Whilst this line:

const CONSTANT_2 : Big = new Big(0);

causes the error:

error TS2304: Cannot find name 'Big'.

What's the problem?

2
  • What are you trying to do in the second one ? Commented Jul 21, 2016 at 18:02
  • Are you importing/referencing that library? Commented Jul 21, 2016 at 18:04

1 Answer 1

4

Look at what the first one is implicitly typed as:

BigJsLibrary.BigJS

Problem

The reason that this doesn't work...

const CONSTANT_2: Big = new Big(0);

...is because Big is defined as a variable in the definition file—not a type:

declare var Big: BigJsLibrary.BigJS;

Solution

If you wish to use explicit typing then you need to reference the created type of the constructor...

const CONSTANT_2: BigJsLibrary.BigJS = new Big(0);

...as is shown in the definition file here:

interface BigJS_Constructors {
    new (value: number): BigJS;
    // etc...
}
Sign up to request clarification or add additional context in comments.

2 Comments

That works, but looks weird. Is there a way to change the .d.ts to use Big like I did?
@Elena add this statement type Big = BigJsLibrary.BigJS;

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.