From 7a8df69b8aca8718d4e862955a12c6944a701f6b Mon Sep 17 00:00:00 2001 From: Muhammad Altabba <24407834+Muhammad-Altabba@users.noreply.github.com> Date: Mon, 25 Nov 2024 07:42:57 +0100 Subject: [PATCH] update typescript version to 5 (#7272) * upgrade typescript to v5 * fix some issues detected by typescript v5 * fix lint issues after the typescript version upgrade --- .gitignore | 3 +- fixtures/utils.ts | 1 + package.json | 2 +- .../web3-account-abstraction/package.json | 2 +- packages/web3-core/package.json | 2 +- .../src/web3_subscription_manager.ts | 1 + .../test/unit/web3_promi_event.test.ts | 2 +- packages/web3-errors/package.json | 2 +- .../web3-errors/src/errors/contract_errors.ts | 1 + packages/web3-eth-abi/package.json | 2 +- packages/web3-eth-abi/src/coders/encode.ts | 2 +- packages/web3-eth-abi/src/utils.ts | 1 + packages/web3-eth-accounts/package.json | 2 +- .../web3-eth-accounts/src/common/common.ts | 13 ++++---- .../web3-eth-accounts/src/common/utils.ts | 11 ++++--- .../src/tx/baseTransaction.ts | 14 ++++---- .../src/tx/eip1559Transaction.ts | 7 ++-- .../src/tx/eip2930Transaction.ts | 7 ++-- .../src/tx/legacyTransaction.ts | 2 +- .../src/tx/transactionFactory.ts | 2 +- packages/web3-eth-accounts/src/tx/types.ts | 2 +- packages/web3-eth-accounts/src/tx/utils.ts | 9 +++--- .../test/unit/common/hardforks.test.ts | 2 +- .../test/unit/common/mergePOS.test.ts | 2 +- .../test/unit/common/timestamp.test.ts | 4 +-- .../test/unit/tx/inputValue.test.ts | 2 +- packages/web3-eth-contract/package.json | 2 +- packages/web3-eth-contract/src/contract.ts | 26 ++++++++------- .../src/contract_log_subscription.ts | 6 ++-- packages/web3-eth-ens/package.json | 2 +- packages/web3-eth-iban/package.json | 2 +- packages/web3-eth-personal/package.json | 2 +- packages/web3-eth/package.json | 2 +- packages/web3-eth/src/rpc_method_wrappers.ts | 12 ++++--- packages/web3-eth/src/utils/decoding.ts | 6 ++-- .../src/utils/reject_if_block_timeout.ts | 2 ++ packages/web3-eth/src/utils/send_tx_helper.ts | 19 ++++++++--- .../web3-eth/src/utils/transaction_builder.ts | 3 +- .../watch_transaction_for_confirmations.ts | 2 +- packages/web3-eth/src/web3_eth.ts | 7 ++-- .../validate_transaction_for_signing.ts | 4 +++ .../web3-eth/test/integration/rpc.test.ts | 4 +-- .../send_transaction.test.ts | 1 + packages/web3-net/package.json | 2 +- packages/web3-providers-http/package.json | 2 +- packages/web3-providers-ipc/package.json | 2 +- packages/web3-providers-ws/package.json | 2 +- packages/web3-rpc-methods/package.json | 2 +- packages/web3-rpc-providers/package.json | 2 +- .../web3-rpc-providers/src/web3_provider.ts | 25 ++++++++++++--- packages/web3-types/package.json | 2 +- packages/web3-types/src/primitives_types.ts | 1 + packages/web3-utils/package.json | 2 +- packages/web3-utils/src/objects.ts | 5 +-- packages/web3-utils/src/validation.ts | 4 +-- .../test/unit/socket_provider.test.ts | 2 +- packages/web3-validator/package.json | 2 +- .../web3-validator/test/unit/utils.test.ts | 2 +- packages/web3/package.json | 2 +- packages/web3/src/web3_eip6963.ts | 32 ++++++++++--------- .../web3/test/benchmark/processingContract.ts | 4 +-- packages/web3/test/e2e/get_block.test.ts | 4 +-- .../web3/test/fixtures/tx-type-15/index.ts | 2 +- scripts/system_tests_utils.ts | 3 +- tools/eslint-config-base-web3/package.json | 2 +- tools/web3-packagetemplate/package.json | 2 +- tools/web3-plugin-example/package.json | 2 +- yarn.lock | 10 +++--- 68 files changed, 191 insertions(+), 131 deletions(-) diff --git a/.gitignore b/.gitignore index 72f88324900..b0c480e7c8f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ tmp lib/ dist/ tsconfig.tsbuildinfo +tsconfig.types.tsbuildinfo # Unsupported lock files package-lock.json @@ -48,4 +49,4 @@ benchmark-data.txt .eslintcache -.history \ No newline at end of file +.history diff --git a/fixtures/utils.ts b/fixtures/utils.ts index 191aed2138e..18d2a766861 100644 --- a/fixtures/utils.ts +++ b/fixtures/utils.ts @@ -18,6 +18,7 @@ export const processAsync = async ( processFunc: ( resolver: (value: unknown) => void, reject: (value: unknown) => void, + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents ) => Promise | unknown, ) => new Promise((resolve, reject) => { diff --git a/package.json b/package.json index 8e741afb9f6..a484b558aca 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "typedoc-plugin-markdown": "^3.17.0", "typedoc-plugin-mdn-links": "^2.0.0", "typedoc-plugin-merge-modules": "^5.1.0", - "typescript": "^4.7.4", + "typescript": "^5.5.4", "utf-8-validate": "^5.0.9", "web3-hardhat-plugin": "^1.0.0", "webpack": "^5.73.0", diff --git a/packages/web3-account-abstraction/package.json b/packages/web3-account-abstraction/package.json index a63d42985b6..530f0a09476 100644 --- a/packages/web3-account-abstraction/package.json +++ b/packages/web3-account-abstraction/package.json @@ -53,7 +53,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" }, "dependencies": { "web3-core": "^4.7.0", diff --git a/packages/web3-core/package.json b/packages/web3-core/package.json index 67cebb09009..856baa3b5b5 100644 --- a/packages/web3-core/package.json +++ b/packages/web3-core/package.json @@ -68,6 +68,6 @@ "jest-when": "^3.5.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" } } diff --git a/packages/web3-core/src/web3_subscription_manager.ts b/packages/web3-core/src/web3_subscription_manager.ts index 8e76498e3c2..754d8e93553 100644 --- a/packages/web3-core/src/web3_subscription_manager.ts +++ b/packages/web3-core/src/web3_subscription_manager.ts @@ -163,6 +163,7 @@ export class Web3SubscriptionManager< const subscription = new Klass(args ?? undefined, { subscriptionManager: this as Web3SubscriptionManager, returnFormat, + // eslint.disable-next-line @typescript-eslint/no-unsafe-any } as any) as InstanceType; await this.addSubscription(subscription); diff --git a/packages/web3-core/test/unit/web3_promi_event.test.ts b/packages/web3-core/test/unit/web3_promi_event.test.ts index 1f597505939..ac4e8b5646f 100644 --- a/packages/web3-core/test/unit/web3_promi_event.test.ts +++ b/packages/web3-core/test/unit/web3_promi_event.test.ts @@ -134,7 +134,7 @@ describe('Web3PromiEvent', () => { }); const f = jest.fn(); - p.finally(f); + await p.finally(f); await p; expect(f).toHaveBeenCalled(); }); diff --git a/packages/web3-errors/package.json b/packages/web3-errors/package.json index c20818ca8a2..17496f4d2cb 100644 --- a/packages/web3-errors/package.json +++ b/packages/web3-errors/package.json @@ -55,6 +55,6 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" } } diff --git a/packages/web3-errors/src/errors/contract_errors.ts b/packages/web3-errors/src/errors/contract_errors.ts index ccd2b7dd46a..85fa96bb43f 100644 --- a/packages/web3-errors/src/errors/contract_errors.ts +++ b/packages/web3-errors/src/errors/contract_errors.ts @@ -150,6 +150,7 @@ export class Eip838ExecutionError extends Web3ContractError { super(error.message || 'Error'); this.name = ('name' in error && error.name) || this.constructor.name; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing this.stack = ('stack' in error && error.stack) || undefined; this.code = error.code; diff --git a/packages/web3-eth-abi/package.json b/packages/web3-eth-abi/package.json index 02bead98645..8423b96294f 100644 --- a/packages/web3-eth-abi/package.json +++ b/packages/web3-eth-abi/package.json @@ -63,6 +63,6 @@ "jest-when": "^3.5.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" } } diff --git a/packages/web3-eth-abi/src/coders/encode.ts b/packages/web3-eth-abi/src/coders/encode.ts index 791c86c827d..1bfb4529220 100644 --- a/packages/web3-eth-abi/src/coders/encode.ts +++ b/packages/web3-eth-abi/src/coders/encode.ts @@ -44,7 +44,7 @@ function inferParamsAbi(params: unknown[]): ReadonlyArray { } as AbiParameter); } else { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - abi.push({ type: toHex(param as any, true) } as AbiParameter); + abi.push({ type: toHex(param as object, true) } as AbiParameter); } }); return abi; diff --git a/packages/web3-eth-abi/src/utils.ts b/packages/web3-eth-abi/src/utils.ts index 79c15b78d78..df8be81995d 100644 --- a/packages/web3-eth-abi/src/utils.ts +++ b/packages/web3-eth-abi/src/utils.ts @@ -253,6 +253,7 @@ export const flattenTypes = ( * returns a string */ export const jsonInterfaceMethodToString = (json: AbiFragment): string => { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing if (isAbiErrorFragment(json) || isAbiEventFragment(json) || isAbiFunctionFragment(json)) { if (json.name?.includes('(')) { return json.name; diff --git a/packages/web3-eth-accounts/package.json b/packages/web3-eth-accounts/package.json index afd61cf1549..5efdc5d2547 100644 --- a/packages/web3-eth-accounts/package.json +++ b/packages/web3-eth-accounts/package.json @@ -54,7 +54,7 @@ "jest-when": "^3.5.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4", + "typescript": "^5.5.4", "web3-providers-ipc": "^4.0.7" }, "dependencies": { diff --git a/packages/web3-eth-accounts/src/common/common.ts b/packages/web3-eth-accounts/src/common/common.ts index 1569050d2f6..7f1b6aee61e 100644 --- a/packages/web3-eth-accounts/src/common/common.ts +++ b/packages/web3-eth-accounts/src/common/common.ts @@ -190,6 +190,7 @@ export class Common extends EventEmitter { * @returns Common */ public static fromGethGenesis( + // eslint-disable-next-line @typescript-eslint/no-explicit-any genesisJson: any, { chain, eips, genesisHash, hardfork, mergeForkIdPostMerge }: GethConfigOpts, ): Common { @@ -811,9 +812,9 @@ export class Common extends EventEmitter { */ // eslint-disable-next-line @typescript-eslint/ban-types public nextHardforkBlockOrTimestamp(_hardfork?: string | Hardfork): bigint | null { - const hardfork = _hardfork ?? this._hardfork; + const hardfork = (_hardfork as Hardfork) ?? this._hardfork; const hfs = this.hardforks(); - let hfIndex = hfs.findIndex(hf => hf.name === hardfork); + let hfIndex = hfs.findIndex(hf => (hf.name as Hardfork) === hardfork); // If the current hardfork is merge, go one behind as merge hf is not part of these // calcs even if the merge hf block is set if (hardfork === Hardfork.Merge) { @@ -842,7 +843,7 @@ export class Common extends EventEmitter { : // eslint-disable-next-line no-null/no-null null; return ( - hf.name !== Hardfork.Merge && + (hf.name as Hardfork) !== Hardfork.Merge && // eslint-disable-next-line no-null/no-null hfTimeOrBlock !== null && hfTimeOrBlock !== undefined && @@ -873,7 +874,7 @@ export class Common extends EventEmitter { */ // eslint-disable-next-line @typescript-eslint/ban-types public nextHardforkBlock(_hardfork?: string | Hardfork): bigint | null { - const hardfork = _hardfork ?? this._hardfork; + const hardfork = (_hardfork as Hardfork) ?? this._hardfork; let hfBlock = this.hardforkBlock(hardfork); // If this is a merge hardfork with block not set, then we fallback to previous hardfork // to find the nextHardforkBlock @@ -905,7 +906,7 @@ export class Common extends EventEmitter { ); // TypeScript can't seem to follow that the hfBlock is not null at this point // eslint-disable-next-line no-null/no-null - return block > hfBlock! && acc === null ? block : acc; + return block > hfBlock && acc === null ? block : acc; // eslint-disable-next-line no-null/no-null }, null); return nextHfBlock; @@ -951,7 +952,7 @@ export class Common extends EventEmitter { typeof blockOrTime === 'number' && blockOrTime !== 0 && blockOrTime !== prevBlockOrTime && - name !== Hardfork.Merge + (name as Hardfork) !== Hardfork.Merge ) { const hfBlockUint8Array = hexToBytes(blockOrTime.toString(16).padStart(16, '0')); hfUint8Array = uint8ArrayConcat(hfUint8Array, hfBlockUint8Array); diff --git a/packages/web3-eth-accounts/src/common/utils.ts b/packages/web3-eth-accounts/src/common/utils.ts index a1d46c36140..44fcadd9154 100644 --- a/packages/web3-eth-accounts/src/common/utils.ts +++ b/packages/web3-eth-accounts/src/common/utils.ts @@ -71,6 +71,7 @@ const intToHex = function (i: number) { * before merge like in kiln genesis * @returns genesis parameters in a `CommonOpts` compliant object */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any function parseGethParams(json: any, mergeForkIdPostMerge = true) { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const { @@ -83,6 +84,7 @@ function parseGethParams(json: any, mergeForkIdPostMerge = true) { baseFeePerGas, }: { name: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any config: any; difficulty: string; mixHash: string; @@ -194,7 +196,7 @@ function parseGethParams(json: any, mergeForkIdPostMerge = true) { }, {}); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const configHardforkNames = Object.keys(config).filter( - // eslint-disable-next-line no-null/no-null, @typescript-eslint/no-unsafe-member-access + // eslint-disable-next-line no-null/no-null, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/prefer-optional-chain key => forkMapRev[key] !== undefined && config[key] !== undefined && config[key] !== null, ); @@ -250,7 +252,7 @@ function parseGethParams(json: any, mergeForkIdPostMerge = true) { // Merge hardfork has to be placed before first hardfork that is dependent on merge const postMergeIndex = params.hardforks.findIndex( // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - (hf: any) => forkMap[hf.name]?.postMerge === true, + hf => forkMap[hf.name]?.postMerge === true, ); if (postMergeIndex !== -1) { params.hardforks.splice(postMergeIndex, 0, mergeConfig as unknown as ConfigHardfork); @@ -272,6 +274,7 @@ function parseGethParams(json: any, mergeForkIdPostMerge = true) { * @param name optional chain name * @returns parsed params */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any export function parseGethGenesis(json: any, name?: string, mergeForkIdPostMerge?: boolean) { try { if (['config', 'difficulty', 'gasLimit', 'alloc'].some(field => !(field in json))) { @@ -282,9 +285,9 @@ export function parseGethGenesis(json: any, name?: string, mergeForkIdPostMerge? json.name = name; } return parseGethParams(json, mergeForkIdPostMerge); - } catch (e: any) { + } catch (e) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions - throw new Error(`Error parsing parameters file: ${e.message}`); + throw new Error(`Error parsing parameters file: ${(e as { message: string }).message}`); } } diff --git a/packages/web3-eth-accounts/src/tx/baseTransaction.ts b/packages/web3-eth-accounts/src/tx/baseTransaction.ts index 5762b8889e9..a39b3cd1ffe 100644 --- a/packages/web3-eth-accounts/src/tx/baseTransaction.ts +++ b/packages/web3-eth-accounts/src/tx/baseTransaction.ts @@ -307,7 +307,7 @@ export abstract class BaseTransaction { // Main signature verification is done in `getSenderPublicKey()` const publicKey = this.getSenderPublicKey(); return unpadUint8Array(publicKey).length !== 0; - } catch (e: any) { + } catch (e) { return false; } } @@ -510,6 +510,7 @@ export abstract class BaseTransaction { } } + // eslint-disable-next-line @typescript-eslint/no-explicit-any protected static _validateNotArray(values: { [key: string]: any }) { const txDataKeys = [ 'nonce', @@ -556,19 +557,19 @@ export abstract class BaseTransaction { let hash = ''; try { hash = this.isSigned() ? bytesToHex(this.hash()) : 'not available (unsigned)'; - } catch (e: any) { + } catch (e) { hash = 'error'; } let isSigned = ''; try { isSigned = this.isSigned().toString(); - } catch (e: any) { + } catch (e) { hash = 'error'; } let hf = ''; try { hf = this.common.hardfork(); - } catch (e: any) { + } catch (e) { hf = 'error'; } @@ -603,15 +604,16 @@ export abstract class BaseTransaction { serialized: Uint8Array, // @ts-expect-error unused variable opts: TxOptions = {}, - // eslint-disable-next-line @typescript-eslint/no-empty-function + // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any ): any {} // eslint-disable-next-line @typescript-eslint/no-explicit-any public static fromTxData( // @ts-expect-error unused variable + // eslint-disable-next-line @typescript-eslint/no-explicit-any txData: any, // @ts-expect-error unused variable opts: TxOptions = {}, - // eslint-disable-next-line @typescript-eslint/no-empty-function + // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any ): any {} } diff --git a/packages/web3-eth-accounts/src/tx/eip1559Transaction.ts b/packages/web3-eth-accounts/src/tx/eip1559Transaction.ts index eafb889220a..6b1b3dd3258 100644 --- a/packages/web3-eth-accounts/src/tx/eip1559Transaction.ts +++ b/packages/web3-eth-accounts/src/tx/eip1559Transaction.ts @@ -104,7 +104,10 @@ export class FeeMarketEIP1559Transaction extends BaseTransaction { ? this.common.chainId() : undefined, ); - } catch (e: any) { + } catch (e) { const msg = this._errorMsg('Invalid Signature'); throw new Error(msg); } diff --git a/packages/web3-eth-accounts/src/tx/transactionFactory.ts b/packages/web3-eth-accounts/src/tx/transactionFactory.ts index 7d3305ec59a..c19e512baa8 100644 --- a/packages/web3-eth-accounts/src/tx/transactionFactory.ts +++ b/packages/web3-eth-accounts/src/tx/transactionFactory.ts @@ -36,7 +36,7 @@ const extraTxTypes: Map> = new Map(); // eslint-disable-next-line @typescript-eslint/no-extraneous-class export class TransactionFactory { // It is not possible to instantiate a TransactionFactory object. - // eslint-disable-next-line @typescript-eslint/no-empty-function, no-useless-constructor + // eslint-disable-next-line no-useless-constructor, @typescript-eslint/no-empty-function private constructor() {} public static typeToInt(txType: Numbers) { diff --git a/packages/web3-eth-accounts/src/tx/types.ts b/packages/web3-eth-accounts/src/tx/types.ts index 830c9e7582f..80bf24d757e 100644 --- a/packages/web3-eth-accounts/src/tx/types.ts +++ b/packages/web3-eth-accounts/src/tx/types.ts @@ -206,7 +206,7 @@ export interface FeeMarketEIP1559TxData extends AccessListEIP2930TxData { * The transaction's gas price, inherited from {@link Transaction}. This property is not used for EIP1559 * transactions and should always be undefined for this specific transaction type. */ - // eslint-disable-next-line @typescript-eslint/ban-types + // eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents gasPrice?: never | null; /** * The maximum inclusion fee per gas (this fee is given to the miner) diff --git a/packages/web3-eth-accounts/src/tx/utils.ts b/packages/web3-eth-accounts/src/tx/utils.ts index 3b2fabbe4ed..d61350d82fa 100644 --- a/packages/web3-eth-accounts/src/tx/utils.ts +++ b/packages/web3-eth-accounts/src/tx/utils.ts @@ -87,7 +87,7 @@ export const verifyAccessList = (accessList: AccessListUint8Array) => { const address = accessListItem[0]; const storageSlots = accessListItem[1]; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/consistent-type-assertions - if ((accessListItem)[2] !== undefined) { + if ((>accessListItem)[2] !== undefined) { throw new Error( 'Access list item cannot have 3 elements. It can only have an address, and an array of storage slots.', ); @@ -115,13 +115,12 @@ export const getAccessListJSON = ( const accessListJSON: { address: HexString; storageKeys: HexString[] }[] = []; // eslint-disable-next-line @typescript-eslint/prefer-for-of for (let index = 0; index < accessList.length; index += 1) { - const item: any = accessList[index]; + const item = accessList[index]; const JSONItem: { address: HexString; storageKeys: HexString[] } = { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/consistent-type-assertions - address: bytesToHex(setLengthLeft(item[0], 20)), + address: bytesToHex(setLengthLeft(item[0], 20)), storageKeys: [], }; - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/prefer-optional-chain + // eslint-disable-next-line @typescript-eslint/prefer-optional-chain const storageSlots: Uint8Array[] = item && item[1]; // eslint-disable-next-line @typescript-eslint/prefer-for-of for (let slot = 0; slot < storageSlots.length; slot += 1) { diff --git a/packages/web3-eth-accounts/test/unit/common/hardforks.test.ts b/packages/web3-eth-accounts/test/unit/common/hardforks.test.ts index 78229bf8d4e..aff6e445c78 100644 --- a/packages/web3-eth-accounts/test/unit/common/hardforks.test.ts +++ b/packages/web3-eth-accounts/test/unit/common/hardforks.test.ts @@ -263,7 +263,7 @@ describe('[Common]: Hardfork logic', () => { c = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Shanghai }); // unschedule shanghai on it to test c.hardforks() - .filter(hf => hf.name === Hardfork.Shanghai) + .filter(hf => (hf.name as Hardfork) === Hardfork.Shanghai) // eslint-disable-next-line array-callback-return .map(hf => { // eslint-disable-next-line no-null/no-null, no-param-reassign diff --git a/packages/web3-eth-accounts/test/unit/common/mergePOS.test.ts b/packages/web3-eth-accounts/test/unit/common/mergePOS.test.ts index a2337c58c32..02882a635ca 100644 --- a/packages/web3-eth-accounts/test/unit/common/mergePOS.test.ts +++ b/packages/web3-eth-accounts/test/unit/common/mergePOS.test.ts @@ -247,7 +247,7 @@ describe('[Common]: Merge/POS specific logic', () => { it('should throw if encounters a double ttd hardfork specification', () => { const c = new Common({ chain: Chain.Sepolia }); // Add the ttd to mergeForkIdTransition which occurs post merge in sepolia - c.hardforks().filter(hf => hf.name === 'mergeForkIdTransition')[0]!['ttd'] = + c.hardforks().filter(hf => hf.name === 'mergeForkIdTransition')[0]['ttd'] = '17000000000000000'; expect(() => { c.setHardforkByBlockNumber(1735371); diff --git a/packages/web3-eth-accounts/test/unit/common/timestamp.test.ts b/packages/web3-eth-accounts/test/unit/common/timestamp.test.ts index 6718119c349..47e262adf13 100644 --- a/packages/web3-eth-accounts/test/unit/common/timestamp.test.ts +++ b/packages/web3-eth-accounts/test/unit/common/timestamp.test.ts @@ -60,7 +60,7 @@ describe('[Common]: Timestamp Hardfork logic', () => { it('forkHash', () => { const mainnet = new Common({ chain: Chain.Mainnet }); const hfs = mainnet.hardforks(); - const mergeIndex = hfs.findIndex(hf => hf.name === Hardfork.Merge); + const mergeIndex = hfs.findIndex(hf => (hf.name as Hardfork) === Hardfork.Merge); const hardforks = hfs.slice(0, mergeIndex + 1).concat([ // Add these hardforks as specified here: // https://github.com/ethereum/EIPs/pull/6122/files @@ -100,7 +100,7 @@ describe('[Common]: Timestamp Hardfork logic', () => { it('setForkHashes', () => { const mainnet = new Common({ chain: Chain.Mainnet }); const hfs = mainnet.hardforks(); - const mergeIndex = hfs.findIndex(hf => hf.name === Hardfork.Merge); + const mergeIndex = hfs.findIndex(hf => (hf.name as Hardfork) === Hardfork.Merge); const hardforks = hfs.slice(0, mergeIndex + 1).concat([ // Add these hardforks as specified here: // https://github.com/ethereum/EIPs/pull/6122/files diff --git a/packages/web3-eth-accounts/test/unit/tx/inputValue.test.ts b/packages/web3-eth-accounts/test/unit/tx/inputValue.test.ts index e39ba839775..c5c2b2b80b1 100644 --- a/packages/web3-eth-accounts/test/unit/tx/inputValue.test.ts +++ b/packages/web3-eth-accounts/test/unit/tx/inputValue.test.ts @@ -248,7 +248,7 @@ test('[Invalid Access Lists]', () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-call tx = tx.sign(hexToBytes('42'.repeat(32))); } - } catch (e: any) { + } catch (e) { tx = TransactionFactory.fromTxData({ type: txType }); if (signed) { // eslint-disable-next-line @typescript-eslint/no-unsafe-call diff --git a/packages/web3-eth-contract/package.json b/packages/web3-eth-contract/package.json index 30db5ffc723..3133720681f 100644 --- a/packages/web3-eth-contract/package.json +++ b/packages/web3-eth-contract/package.json @@ -68,7 +68,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4", + "typescript": "^5.5.4", "web3-eth-accounts": "^4.3.0", "web3-providers-ws": "^4.0.8" } diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index cff3a440bfe..bc0cde9022a 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -21,6 +21,7 @@ import { Web3PromiEvent, Web3ConfigEvent, Web3SubscriptionManager, + Web3SubscriptionConstructor, } from 'web3-core'; import { ContractExecutionError, @@ -128,9 +129,11 @@ type ContractBoundMethod< Method extends ContractMethod = ContractMethod, > = ( ...args: Abi extends undefined - ? any[] + ? // eslint-disable-next-line @typescript-eslint/no-explicit-any + any[] : Method['Inputs'] extends never - ? any[] + ? // eslint-disable-next-line @typescript-eslint/no-explicit-any + any[] : Method['Inputs'] ) => Method['Abi']['stateMutability'] extends 'payable' | 'pure' ? PayableMethodObject @@ -737,7 +740,7 @@ export class Contract * ``` */ public clone() { - let newContract: Contract; + let newContract: Contract; if (this.options.address) { newContract = new Contract( [...this._jsonInterface, ...this._errorsInterface] as unknown as Abi, @@ -930,12 +933,12 @@ export class Contract param2?: Omit | ReturnFormat, param3?: ReturnFormat, ): Promise<(string | EventLog)[]> { - const eventName = typeof param1 === 'string' ? param1 : ALL_EVENTS; + const eventName: string = typeof param1 === 'string' ? param1 : ALL_EVENTS; const options = // eslint-disable-next-line no-nested-ternary typeof param1 !== 'string' && !isDataFormat(param1) - ? param1 + ? (param1 as Omit) : !isDataFormat(param2) ? param2 : {}; @@ -955,7 +958,7 @@ export class Contract ) as AbiEventFragment & { signature: string }); if (!abi) { - throw new Web3ContractError(`Event ${eventName} not found.`); + throw new Web3ContractError(`Event ${String(eventName)} not found.`); } const { fromBlock, toBlock, topics, address } = encodeEventABI( @@ -1059,11 +1062,11 @@ export class Contract // make constant and payable backwards compatible abi.constant = - abi.stateMutability === 'view' ?? - abi.stateMutability === 'pure' ?? + abi.stateMutability === 'view' || + abi.stateMutability === 'pure' || abi.constant; - abi.payable = abi.stateMutability === 'payable' ?? abi.payable; + abi.payable = abi.stateMutability === 'payable' || abi.payable; this._overloadedMethodAbis.set(abi.name, [ ...(this._overloadedMethodAbis.get(abi.name) ?? []), abi, @@ -1438,10 +1441,11 @@ export class Contract jsonInterface: this._jsonInterface, }, { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment subscriptionManager: this.subscriptionManager as Web3SubscriptionManager< unknown, - any + { + [key: string]: Web3SubscriptionConstructor; + } >, returnFormat, }, diff --git a/packages/web3-eth-contract/src/contract_log_subscription.ts b/packages/web3-eth-contract/src/contract_log_subscription.ts index 8010309c7cb..b1994a81af8 100644 --- a/packages/web3-eth-contract/src/contract_log_subscription.ts +++ b/packages/web3-eth-contract/src/contract_log_subscription.ts @@ -145,8 +145,10 @@ export class ContractLogsSubscription extends Web3Subscription< returnFormat?: DataFormat; }, ) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - super(args, options as any); + super( + args, + options as { subscriptionManager: Web3SubscriptionManager; returnFormat?: DataFormat }, + ); this.address = args.address; this.topics = args.topics; diff --git a/packages/web3-eth-ens/package.json b/packages/web3-eth-ens/package.json index e18474e0140..b509be62457 100644 --- a/packages/web3-eth-ens/package.json +++ b/packages/web3-eth-ens/package.json @@ -55,7 +55,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" }, "dependencies": { "@adraffy/ens-normalize": "^1.8.8", diff --git a/packages/web3-eth-iban/package.json b/packages/web3-eth-iban/package.json index 81e65c298b1..b5d1013c396 100644 --- a/packages/web3-eth-iban/package.json +++ b/packages/web3-eth-iban/package.json @@ -53,7 +53,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" }, "dependencies": { "web3-errors": "^1.1.3", diff --git a/packages/web3-eth-personal/package.json b/packages/web3-eth-personal/package.json index 2a1f3000308..cee759d16af 100644 --- a/packages/web3-eth-personal/package.json +++ b/packages/web3-eth-personal/package.json @@ -61,7 +61,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4", + "typescript": "^5.5.4", "web3-providers-ws": "^4.0.8" } } diff --git a/packages/web3-eth/package.json b/packages/web3-eth/package.json index 6c598d767e7..536bb91aee4 100644 --- a/packages/web3-eth/package.json +++ b/packages/web3-eth/package.json @@ -58,7 +58,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4", + "typescript": "^5.5.4", "web3-providers-http": "^4.2.0" }, "dependencies": { diff --git a/packages/web3-eth/src/rpc_method_wrappers.ts b/packages/web3-eth/src/rpc_method_wrappers.ts index 9931c56364f..b8dddb70589 100644 --- a/packages/web3-eth/src/rpc_method_wrappers.ts +++ b/packages/web3-eth/src/rpc_method_wrappers.ts @@ -598,11 +598,13 @@ export function sendTransaction< transaction = await transactionMiddleware.processTransaction(transaction); } - let transactionFormatted: + let transactionFormatted: FormatType< | Transaction | TransactionWithFromLocalWalletIndex | TransactionWithToLocalWalletIndex - | TransactionWithFromAndToLocalWalletIndex = formatTransaction( + | TransactionWithFromAndToLocalWalletIndex, + ReturnFormat + > = formatTransaction( { ...transaction, from: getTransactionFromOrToAttr('from', web3Context, transaction), @@ -612,13 +614,13 @@ export function sendTransaction< { transactionSchema: web3Context.config.customTransactionSchema, }, - ); + ) as FormatType; try { - transactionFormatted = await sendTxHelper.populateGasPrice({ + transactionFormatted = (await sendTxHelper.populateGasPrice({ transaction, transactionFormatted, - }); + })) as FormatType; await sendTxHelper.checkRevertBeforeSending( transactionFormatted as TransactionCall, diff --git a/packages/web3-eth/src/utils/decoding.ts b/packages/web3-eth/src/utils/decoding.ts index f4b61c0a5ac..1f8c33c19ec 100644 --- a/packages/web3-eth/src/utils/decoding.ts +++ b/packages/web3-eth/src/utils/decoding.ts @@ -83,9 +83,9 @@ export const decodeEventABI = ( returnValues: decodeLog([...(modifiedEvent.inputs ?? [])], data.data, argTopics), event: modifiedEvent.name, signature: - modifiedEvent.anonymous || !data.topics || data.topics.length === 0 || !data.topics[0] - ? undefined - : data.topics[0], + !modifiedEvent.anonymous && data.topics?.length > 0 && data.topics[0] + ? data.topics[0] + : undefined, raw: { data: data.data, diff --git a/packages/web3-eth/src/utils/reject_if_block_timeout.ts b/packages/web3-eth/src/utils/reject_if_block_timeout.ts index e3563ca2a1a..72ef1a3bd02 100644 --- a/packages/web3-eth/src/utils/reject_if_block_timeout.ts +++ b/packages/web3-eth/src/utils/reject_if_block_timeout.ts @@ -168,8 +168,10 @@ export async function rejectIfBlockTimeout( (provider as Web3BaseProvider).supportsSubscriptions?.() && web3Context.enableExperimentalFeatures.useSubscriptionWhenCheckingBlockTimeout ) { + // eslint-disable-next-line @typescript-eslint/no-floating-promises callingRes = await resolveBySubscription(web3Context, starterBlockNumber, transactionHash); } else { + // eslint-disable-next-line @typescript-eslint/no-floating-promises callingRes = resolveByPolling(web3Context, starterBlockNumber, transactionHash); } return callingRes; diff --git a/packages/web3-eth/src/utils/send_tx_helper.ts b/packages/web3-eth/src/utils/send_tx_helper.ts index e28b353cda1..75f69ddb0f2 100644 --- a/packages/web3-eth/src/utils/send_tx_helper.ts +++ b/packages/web3-eth/src/utils/send_tx_helper.ts @@ -45,6 +45,7 @@ import { import { ethRpcMethods } from 'web3-rpc-methods'; import { + InternalTransaction, SendSignedTransactionEvents, SendTransactionEvents, SendTransactionOptions, @@ -150,7 +151,12 @@ export class SendTxHelper< public emitSending(tx: TxType | HexString) { if (this.promiEvent.listenerCount('sending') > 0) { - this.promiEvent.emit('sending', tx); + this.promiEvent.emit( + 'sending', + tx as + | SendSignedTransactionEvents['sending'] + | SendTransactionEvents['sending'], + ); } } @@ -174,7 +180,7 @@ export class SendTxHelper< // @TODO gasPrice, maxPriorityFeePerGas, maxFeePerGas // should not be included if undefined, but currently are ...(await getTransactionGasPricing( - transactionFormatted, + transactionFormatted as InternalTransaction, this.web3Context, ETH_DATA_FORMAT, )), @@ -192,7 +198,7 @@ export class SendTxHelper< tx: TxType; }) { if (wallet) { - const signedTransaction = await wallet.signTransaction(tx); + const signedTransaction = await wallet.signTransaction(tx as Transaction); return trySendTransaction( this.web3Context, @@ -216,7 +222,12 @@ export class SendTxHelper< public emitSent(tx: TxType | HexString) { if (this.promiEvent.listenerCount('sent') > 0) { - this.promiEvent.emit('sent', tx); + this.promiEvent.emit( + 'sent', + tx as + | SendSignedTransactionEvents['sent'] + | SendTransactionEvents['sent'], + ); } } public emitTransactionHash(hash: string & Uint8Array) { diff --git a/packages/web3-eth/src/utils/transaction_builder.ts b/packages/web3-eth/src/utils/transaction_builder.ts index 0d459017b4a..c4bc2d88fb4 100644 --- a/packages/web3-eth/src/utils/transaction_builder.ts +++ b/packages/web3-eth/src/utils/transaction_builder.ts @@ -64,7 +64,8 @@ export const getTransactionFromOrToAttr = ( privateKey?: HexString | Uint8Array, ): Address | undefined => { if (transaction !== undefined && attr in transaction && transaction[attr] !== undefined) { - if (typeof transaction[attr] === 'string' && isAddress(transaction[attr] as string)) { + if (typeof transaction[attr] === 'string' && isAddress(transaction[attr])) { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion return transaction[attr] as Address; } if (!isHexStrict(transaction[attr] as string) && isNumber(transaction[attr] as Numbers)) { diff --git a/packages/web3-eth/src/utils/watch_transaction_for_confirmations.ts b/packages/web3-eth/src/utils/watch_transaction_for_confirmations.ts index 01ca39f8894..4dd94dd3394 100644 --- a/packages/web3-eth/src/utils/watch_transaction_for_confirmations.ts +++ b/packages/web3-eth/src/utils/watch_transaction_for_confirmations.ts @@ -62,7 +62,7 @@ export function watchTransactionForConfirmations< returnFormat, ), latestBlockHash: format({ format: 'bytes32' }, transactionReceipt.blockHash, returnFormat), - }); + } as Web3PromiEventEventType['confirmation']); // so a subscription for newBlockHeaders can be made instead of polling const provider: Web3BaseProvider = web3Context.requestManager.provider as Web3BaseProvider; diff --git a/packages/web3-eth/src/web3_eth.ts b/packages/web3-eth/src/web3_eth.ts index 6320ff4f524..89d4f1450b4 100644 --- a/packages/web3-eth/src/web3_eth.ts +++ b/packages/web3-eth/src/web3_eth.ts @@ -104,14 +104,17 @@ export class Web3Eth extends Web3Context | Web3ContextInitOptions | string, ) { if ( typeof providerOrContext === 'string' || + // eslint-disable-next-line @typescript-eslint/no-explicit-any isSupportedProvider(providerOrContext as SupportedProviders) ) { // @ts-expect-error disable the error: "A 'super' call must be a root-level statement within a constructor of a derived class that contains initialized properties, parameter properties, or private identifiers." super({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any provider: providerOrContext as SupportedProviders, registeredSubscriptions, }); @@ -1921,8 +1924,8 @@ export class Web3Eth extends Web3Context { this.getPastLogs(args) diff --git a/packages/web3-eth/test/fixtures/validate_transaction_for_signing.ts b/packages/web3-eth/test/fixtures/validate_transaction_for_signing.ts index f22d5ac60cc..3e341cbcc3b 100644 --- a/packages/web3-eth/test/fixtures/validate_transaction_for_signing.ts +++ b/packages/web3-eth/test/fixtures/validate_transaction_for_signing.ts @@ -35,6 +35,7 @@ import { export const invalidTransactionObject: any[] = ['42', false, '0x0', BigInt(42), () => {}]; export const validateCustomChainInfoData: [ + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents FormatType | any, undefined | MissingCustomChainError | MissingCustomChainIdError | ChainIdMismatchError, ][] = [ @@ -178,6 +179,7 @@ export const validateCustomChainInfoData: [ ]; export const validateChainInfoData: [ + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents FormatType | any, undefined | CommonOrChainAndHardforkError | MissingChainOrHardforkError, ][] = [ @@ -304,6 +306,7 @@ export const validateChainInfoData: [ ]; export const validateGasData: [ + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents FormatType | any, ( | undefined @@ -727,6 +730,7 @@ export const validateGasData: [ ]; export const invalidNonceOrChainIdData: [ + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents FormatType | any, undefined | InvalidNonceOrChainIdError, ][] = [ diff --git a/packages/web3-eth/test/integration/rpc.test.ts b/packages/web3-eth/test/integration/rpc.test.ts index eba6792a2f8..cc4fa2a76f4 100644 --- a/packages/web3-eth/test/integration/rpc.test.ts +++ b/packages/web3-eth/test/integration/rpc.test.ts @@ -380,10 +380,10 @@ describe('rpc', () => { times: 1, }); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const res: TransactionReceipt = (await web3Eth.getTransactionReceipt( + const res: TransactionReceipt = await web3Eth.getTransactionReceipt( // TODO: add more scenarios in future release with block number receipt.transactionHash as string, - ))!; + ); validateReceipt(res); expect(res?.transactionHash).toBe(receipt.transactionHash); }); diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/send_transaction.test.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/send_transaction.test.ts index e9b60f97e74..134910f19f7 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/send_transaction.test.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/send_transaction.test.ts @@ -66,6 +66,7 @@ describe('sendTransaction', () => { ); if ( + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing sendTransactionOptions?.ignoreGasPricing || !isNullish(inputTransaction.gasPrice) || (!isNullish(inputTransaction.maxPriorityFeePerGas) && diff --git a/packages/web3-net/package.json b/packages/web3-net/package.json index 952457f72be..c1670f15f9f 100644 --- a/packages/web3-net/package.json +++ b/packages/web3-net/package.json @@ -53,7 +53,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" }, "dependencies": { "web3-core": "^4.4.0", diff --git a/packages/web3-providers-http/package.json b/packages/web3-providers-http/package.json index c94d24177e8..9e9631108f1 100644 --- a/packages/web3-providers-http/package.json +++ b/packages/web3-providers-http/package.json @@ -57,7 +57,7 @@ "jest-fetch-mock": "^3.0.3", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" }, "dependencies": { "cross-fetch": "^4.0.0", diff --git a/packages/web3-providers-ipc/package.json b/packages/web3-providers-ipc/package.json index 395156d6598..82b2d9aada2 100644 --- a/packages/web3-providers-ipc/package.json +++ b/packages/web3-providers-ipc/package.json @@ -53,7 +53,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" }, "dependencies": { "web3-errors": "^1.1.3", diff --git a/packages/web3-providers-ws/package.json b/packages/web3-providers-ws/package.json index 49595cc21df..da21e8db8bb 100644 --- a/packages/web3-providers-ws/package.json +++ b/packages/web3-providers-ws/package.json @@ -58,7 +58,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4", + "typescript": "^5.5.4", "web3-providers-http": "^4.1.0" }, "dependencies": { diff --git a/packages/web3-rpc-methods/package.json b/packages/web3-rpc-methods/package.json index 3a05060f2c2..6931807ee1c 100644 --- a/packages/web3-rpc-methods/package.json +++ b/packages/web3-rpc-methods/package.json @@ -53,7 +53,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" }, "dependencies": { "web3-core": "^4.4.0", diff --git a/packages/web3-rpc-providers/package.json b/packages/web3-rpc-providers/package.json index 9339d4a3fb3..028c7f49050 100644 --- a/packages/web3-rpc-providers/package.json +++ b/packages/web3-rpc-providers/package.json @@ -54,7 +54,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" }, "dependencies": { "web3-errors": "^1.3.0", diff --git a/packages/web3-rpc-providers/src/web3_provider.ts b/packages/web3-rpc-providers/src/web3_provider.ts index 922d8217256..41c5513bbb7 100644 --- a/packages/web3-rpc-providers/src/web3_provider.ts +++ b/packages/web3-rpc-providers/src/web3_provider.ts @@ -141,9 +141,15 @@ export abstract class Web3ExternalProvider< listener: Web3Eip1193ProviderEventCallback, ): void; public once(_type: string, _listener: unknown): void { - if (this.provider?.once) + if (this.provider?.once) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - this.provider.once(_type, _listener as any); + this.provider.once( + _type, + _listener as + | Web3Eip1193ProviderEventCallback + | Web3ProviderEventCallback, + ); + } } public removeAllListeners?(_type: string): void { if (this.provider?.removeAllListeners) this.provider.removeAllListeners(_type); @@ -183,7 +189,12 @@ export abstract class Web3ExternalProvider< public on(_type: unknown, _listener: unknown): void { if (this.provider) // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - this.provider.on(_type as any, _listener as any); + this.provider.on( + _type as string, + _listener as + | Web3Eip1193ProviderEventCallback + | Web3ProviderMessageEventCallback, + ); } public removeListener( type: 'disconnect', @@ -207,7 +218,11 @@ export abstract class Web3ExternalProvider< ): void; public removeListener(_type: unknown, _listener: unknown): void { if (this.provider) - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - this.provider.removeListener(_type as any, _listener as any); + this.provider.removeListener( + _type as string, + _listener as + | Web3Eip1193ProviderEventCallback + | Web3ProviderEventCallback, + ); } } diff --git a/packages/web3-types/package.json b/packages/web3-types/package.json index 31c8f217726..5fa5b7e1da7 100644 --- a/packages/web3-types/package.json +++ b/packages/web3-types/package.json @@ -54,6 +54,6 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" } } diff --git a/packages/web3-types/src/primitives_types.ts b/packages/web3-types/src/primitives_types.ts index 387900e7b66..1150994906b 100644 --- a/packages/web3-types/src/primitives_types.ts +++ b/packages/web3-types/src/primitives_types.ts @@ -15,6 +15,7 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ +// TODO: consider using `0x${string}` instead of `string` for HexString export type HexString = string; export type Bytes = Uint8Array | HexString; export type Numbers = number | bigint | string | HexString; diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index d9c12c25ac8..c49a2929bf6 100644 --- a/packages/web3-utils/package.json +++ b/packages/web3-utils/package.json @@ -60,7 +60,7 @@ "js-sha3": "^0.8.0", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" }, "dependencies": { "ethereum-cryptography": "^2.0.0", diff --git a/packages/web3-utils/src/objects.ts b/packages/web3-utils/src/objects.ts index feda5510e4f..75fe0e81187 100644 --- a/packages/web3-utils/src/objects.ts +++ b/packages/web3-utils/src/objects.ts @@ -48,10 +48,7 @@ export const mergeDeep = ( if (!result[key]) { result[key] = {}; } - result[key] = mergeDeep( - result[key] as Record, - src[key] as Record, - ); + result[key] = mergeDeep(result[key] as Record, src[key]); } else if (!isNullish(src[key]) && Object.hasOwnProperty.call(src, key)) { if (Array.isArray(src[key]) || src[key] instanceof TypedArray) { result[key] = (src[key] as unknown[]).slice(0); diff --git a/packages/web3-utils/src/validation.ts b/packages/web3-utils/src/validation.ts index 57e91aae76d..1cfd4615ea4 100644 --- a/packages/web3-utils/src/validation.ts +++ b/packages/web3-utils/src/validation.ts @@ -134,10 +134,10 @@ export const compareBlockNumbers = (blockA: BlockNumberOrTag, blockB: BlockNumbe ) { return 0; } - if (blockA === 'earliest' && blockB > 0) { + if (blockA === 'earliest') { return -1; } - if (blockB === 'earliest' && blockA > 0) { + if (blockB === 'earliest') { return 1; } diff --git a/packages/web3-utils/test/unit/socket_provider.test.ts b/packages/web3-utils/test/unit/socket_provider.test.ts index 19529f4181a..f65fa4c3a79 100644 --- a/packages/web3-utils/test/unit/socket_provider.test.ts +++ b/packages/web3-utils/test/unit/socket_provider.test.ts @@ -48,7 +48,7 @@ class TestProvider extends SocketProvider { protected _sendToSocket(_payload: Web3APIPayload): void {} // eslint-disable-next-line protected _parseResponses(_event: { data: string } | undefined): JsonRpcResponse[] { - if (!_event || !_event.data) { + if (!_event?.data) { return []; } const returnValues: JsonRpcResponse[] = []; diff --git a/packages/web3-validator/package.json b/packages/web3-validator/package.json index 4a12b604981..bff4e5a7c59 100644 --- a/packages/web3-validator/package.json +++ b/packages/web3-validator/package.json @@ -62,6 +62,6 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4" + "typescript": "^5.5.4" } } diff --git a/packages/web3-validator/test/unit/utils.test.ts b/packages/web3-validator/test/unit/utils.test.ts index eac7d652bbf..fb61c9da776 100644 --- a/packages/web3-validator/test/unit/utils.test.ts +++ b/packages/web3-validator/test/unit/utils.test.ts @@ -107,7 +107,7 @@ describe('utils', () => { it.each(validHexStrictDataWithNumber.map(tuple => [tuple[1], tuple[0]]))( 'valid numbers and bigints', (input, res) => { - expect(numberToHex(input)).toEqual((res as string).toLowerCase()); + expect(numberToHex(input)).toEqual(res.toLowerCase()); }, ); diff --git a/packages/web3/package.json b/packages/web3/package.json index 7e4be7ba12d..8669034a092 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -82,7 +82,7 @@ "jest-extended": "^3.0.1", "prettier": "^2.7.1", "ts-jest": "^29.1.1", - "typescript": "^4.7.4", + "typescript": "^5.5.4", "web3-providers-ipc": "^4.0.7" }, "dependencies": { diff --git a/packages/web3/src/web3_eip6963.ts b/packages/web3/src/web3_eip6963.ts index 2e9a2a391f8..368b075d4ec 100644 --- a/packages/web3/src/web3_eip6963.ts +++ b/packages/web3/src/web3_eip6963.ts @@ -63,20 +63,19 @@ export const requestEIP6963Providers = async (): Promise { - eip6963ProvidersMap.set(event.detail.info.uuid, event.detail); - - const newEvent: EIP6963ProvidersMapUpdateEvent = new CustomEvent( - web3ProvidersMapUpdated, - { detail: eip6963ProvidersMap }, - ); - - window.dispatchEvent(newEvent); - resolve(eip6963ProvidersMap); - }, - ); + window.addEventListener(Eip6963EventName.eip6963announceProvider, (( + event: EIP6963AnnounceProviderEvent, + ) => { + eip6963ProvidersMap.set(event.detail.info.uuid, event.detail); + + const newEvent: EIP6963ProvidersMapUpdateEvent = new CustomEvent( + web3ProvidersMapUpdated, + { detail: eip6963ProvidersMap }, + ); + + window.dispatchEvent(newEvent); + resolve(eip6963ProvidersMap); + }) as EventListenerOrEventListenerObject); window.dispatchEvent(new Event(Eip6963EventName.eip6963requestProvider)); }); @@ -89,5 +88,8 @@ export const onNewProviderDiscovered = ( 'window object not available, EIP-6963 is intended to be used within a browser', ); } - window.addEventListener(web3ProvidersMapUpdated as any, callback); + window.addEventListener( + web3ProvidersMapUpdated, + callback as EventListenerOrEventListenerObject, + ); }; diff --git a/packages/web3/test/benchmark/processingContract.ts b/packages/web3/test/benchmark/processingContract.ts index 2f1966cdf04..60311fcc46e 100644 --- a/packages/web3/test/benchmark/processingContract.ts +++ b/packages/web3/test/benchmark/processingContract.ts @@ -14,13 +14,13 @@ GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { AbiFunctionFragment, ContractOptions } from 'web3-types'; +import { AbiConstructorFragment, AbiFunctionFragment, ContractOptions } from 'web3-types'; // eslint-disable-next-line import { getSendTxParams, getEthTxCallParams } from 'web3-eth-contract'; import { BasicAbi, BasicBytecode } from '../shared_fixtures/build/Basic'; import accounts from '../shared_fixtures/accounts.json'; -const abiConstructor = BasicAbi.find(j => j.type === 'constructor') as AbiFunctionFragment; +const abiConstructor = BasicAbi.find(j => j.type === 'constructor') as AbiConstructorFragment; const abiSendMethod = BasicAbi.find( j => j.type === 'function' && j.name === 'firesMultiValueEvent', ) as AbiFunctionFragment; diff --git a/packages/web3/test/e2e/get_block.test.ts b/packages/web3/test/e2e/get_block.test.ts index 33d78291b36..eb9cd09a50a 100644 --- a/packages/web3/test/e2e/get_block.test.ts +++ b/packages/web3/test/e2e/get_block.test.ts @@ -57,7 +57,7 @@ describe(`${getSystemTestBackend()} tests - getBlock`, () => { | 'blockHash' | 'blockNumber'; hydrated: boolean; - format: string; + format: FMT_NUMBER; }>({ block: ['earliest', 'latest', 'safe', 'finalized', 'blockHash', 'blockNumber'], hydrated: [true, false], @@ -66,7 +66,7 @@ describe(`${getSystemTestBackend()} tests - getBlock`, () => { )('getBlock', async ({ hydrated, block, format }) => { const result = { ...(await web3.eth.getBlock(blockData[block], hydrated, { - number: format as FMT_NUMBER, + number: format, bytes: FMT_BYTES.HEX, })), }; diff --git a/packages/web3/test/fixtures/tx-type-15/index.ts b/packages/web3/test/fixtures/tx-type-15/index.ts index 1d7dd778067..479a5badfab 100644 --- a/packages/web3/test/fixtures/tx-type-15/index.ts +++ b/packages/web3/test/fixtures/tx-type-15/index.ts @@ -400,7 +400,7 @@ export class SomeNewTxTypeTransaction extends BaseTransaction