Closed claytn closed 4 years ago
It depends on the location of the library and the typescript options used, but try:
import BigNumber from "./bignumber.js/bignumber";
I've imported the library as an npm module, so that won't work in my case
import BigNumber from "bignumber.js";
should work if the library is in a node_modules directory and the moduleResolution option is "Node".
moduleResolution is set to "node" in my tsconfig. The problem seems to be that no matter what import I go with its only importing the bignumber.d.ts
file which only contains the type definitions and not the implementation.
I can get around this issue if I directly use require('bignumber.js')
, but I don't get the typescript support with it obviously.
I didn't realize this library had it's types available in DefinitelyTyped. Once I installed the types as a dev dependency using the regular import seems to be working just fine.
yarn add -D @types/bignumber.js
// index.ts
import { BigNumber } from 'bignumber.js'
(new BigNumber(5)).plus(10).toString() // "15"
^ this works just fine now 😄
thanks for the help! I'll update the repo README soon with a Typescript specific section that includes these instructions 👍
This library works just fine with Typescript as it is without the @types/bignumber.js
, as can be verified by creating a simple test project.
When installed from npm the library already contains the type declarations, bignumber.d.ts, and the package.json correctly references them with "types": "bignumber.d.ts"
.
I do not know what the problem was with your project configuration but it is not an issue with this library.
I will add to the README presently to make it explicit that after a npm install the library can be imported using
import BigNumber from "bignumber.js";
BigNumber.js Version: 9.0.0
In my Typescript+React Native project I'm trying to pull in the BigNumber library, but none of the helper functions are available. When doing something like...
I get an error saying:
TypeError: a.plus is not a function (In a.plus(1), a.plus is undefined)
I have run across old issues where other users have said I need to update my import statement. I've tried all of the following imports and none of them have fixed the above issue.
Has anyone else run into this problem? Thanks 😊