Skip to content

Commit 5e5dfd5

Browse files
committed
fix(controller-utils): use overload signatures where appropriate
1 parent f0fee88 commit 5e5dfd5

File tree

1 file changed

+18
-4
lines changed
  • packages/controller-utils/src

1 file changed

+18
-4
lines changed

packages/controller-utils/src/util.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ export function isSafeChainId(chainId: Hex): boolean {
7070
*/
7171
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
7272
// eslint-disable-next-line @typescript-eslint/naming-convention
73-
export function BNToHex(inputBn: BN | BN4 | BigNumber) {
73+
export function BNToHex(inputBn: BN | BN4 | BigNumber): string {
7474
return add0x(inputBn.toString(16));
7575
}
7676

77+
function getBNImplementation(targetBN: BN4): typeof BN4;
78+
function getBNImplementation(targetBN: BN): typeof BN;
7779
/**
7880
* Return the bn.js library responsible for the BN in question
7981
* @param targetBN - A BN instance
@@ -83,6 +85,16 @@ function getBNImplementation(targetBN: BN | BN4): typeof BN4 | typeof BN {
8385
return Object.keys(targetBN).includes('_strip') ? BN4 : BN;
8486
}
8587

88+
export function fractionBN(
89+
targetBN: BN,
90+
numerator: number | string,
91+
denominator: number | string,
92+
): BN;
93+
export function fractionBN(
94+
targetBN: BN4,
95+
numerator: number | string,
96+
denominator: number | string,
97+
): BN4;
8698
/**
8799
* Used to multiply a BN by a fraction.
88100
*
@@ -95,13 +107,13 @@ export function fractionBN(
95107
targetBN: BN | BN4,
96108
numerator: number | string,
97109
denominator: number | string,
98-
) {
110+
): BN | BN4 {
111+
// @ts-expect-error - Signature overload confusion
99112
const BNImplementation = getBNImplementation(targetBN);
100113

101-
// @ts-expect-error - Incompatible constructor signatures are actually compatible here
102114
const numBN = new BNImplementation(numerator);
103-
// @ts-expect-error - Incompatible constructor signatures are actually compatible here
104115
const denomBN = new BNImplementation(denominator);
116+
// @ts-expect-error - BNImplementation gets unexpected typed
105117
return targetBN.mul(numBN).div(denomBN);
106118
}
107119

@@ -206,6 +218,8 @@ export function hexToText(hex: string) {
206218
}
207219
}
208220

221+
export function fromHex(value: string | BN): BN;
222+
export function fromHex(value: BN4): BN4;
209223
/**
210224
* Parses a hex string and converts it into a number that can be operated on in a bignum-safe,
211225
* base-10 way.

0 commit comments

Comments
 (0)