Skip to content

Commit

Permalink
fix(controller-utils): use overload signatures where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Oct 24, 2024
1 parent 3c66f62 commit 1aac54e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/controller-utils/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function isSafeChainId(chainId: Hex): boolean {
*/
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/naming-convention
export function BNToHex(inputBn: BN | BN4 | BigNumber) {
export function BNToHex(inputBn: BN | BN4 | BigNumber): string {
return add0x(inputBn.toString(16));
}

Expand All @@ -79,6 +79,8 @@ export function BNToHex(inputBn: BN | BN4 | BigNumber) {
* @param targetBN - A BN instance
* @returns A bn.js instance
*/
function getBNImplementation(targetBN: BN4): typeof BN4;
function getBNImplementation(targetBN: BN): typeof BN;
function getBNImplementation(targetBN: BN | BN4): typeof BN4 | typeof BN {

Check failure on line 84 in packages/controller-utils/src/util.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Missing JSDoc comment
return Object.keys(targetBN).includes('_strip') ? BN4 : BN;
}
Expand All @@ -91,17 +93,27 @@ function getBNImplementation(targetBN: BN | BN4): typeof BN4 | typeof BN {
* @param denominator - Denominator of the fraction multiplier.
* @returns Product of the multiplication.
*/
export function fractionBN(
targetBN: BN,
numerator: number | string,
denominator: number | string,
): BN;
export function fractionBN(
targetBN: BN4,
numerator: number | string,
denominator: number | string,
): BN4;
export function fractionBN(

Check failure on line 106 in packages/controller-utils/src/util.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Missing JSDoc comment
targetBN: BN | BN4,
numerator: number | string,
denominator: number | string,
) {
): BN | BN4 {
// @ts-expect-error - Signature overload confusion
const BNImplementation = getBNImplementation(targetBN);

// @ts-expect-error - Incompatible constructor signatures are actually compatible here
const numBN = new BNImplementation(numerator);
// @ts-expect-error - Incompatible constructor signatures are actually compatible here
const denomBN = new BNImplementation(denominator);
// @ts-expect-error - BNImplementation gets unexpected typed
return targetBN.mul(numBN).div(denomBN);
}

Expand Down Expand Up @@ -213,6 +225,8 @@ export function hexToText(hex: string) {
* @param value - A base-16 number encoded as a string.
* @returns The number as a BN object in base-16 mode.
*/
export function fromHex(value: string | BN): BN;
export function fromHex(value: BN4): BN4;
export function fromHex(value: string | BN | BN4): BN | BN4 {

Check failure on line 230 in packages/controller-utils/src/util.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Missing JSDoc comment
if (BN.isBN(value)) {
return value;
Expand Down

0 comments on commit 1aac54e

Please sign in to comment.