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?
Look at what the first one is implicitly typed as:
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...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.