Note: Despite the recommendation to use BigInts instead of
bn.js
, I am currently working with a legacy codebase that has not been migrated yet.
Below is the code that compiles and executes without any issues:
import { BN } from "bn.js";
import assert from "node:assert/strict";
const one = new BN(1);
one.cmp(one);
export const assertBigNumberEqual = (actual: BN, expected: BN) => {
return assert(actual.cmp(expected) === 0);
};
console.log("this will work");
assertBigNumberEqual(new BN(1), new BN(1));
console.log("yay it worked");
console.log("this will throw an error");
console.log(assertBigNumberEqual(new BN(1), new BN(2)));
However, TypeScript raises a warning on the following function:
export const assertBigNumberEqual = (actual: BN, expected: BN) => {
return assert(actual.cmp(expected) === 0);
};
'BN' refers to a value, but is being used as a type here. Did you mean 'typeof BN'? ts(2749)
Using typeof BN
as the parameter type would cause issues with actual.cmp
.
I am looking for a solution to resolve this TypeScript warning without resorting to @ts-ignore
.
How can I address the TypeScript warning?