Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 7a8df69

Browse files
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
1 parent 984cb7c commit 7a8df69

File tree

68 files changed

+191
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+191
-131
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ tmp
3434
lib/
3535
dist/
3636
tsconfig.tsbuildinfo
37+
tsconfig.types.tsbuildinfo
3738

3839
# Unsupported lock files
3940
package-lock.json
@@ -48,4 +49,4 @@ benchmark-data.txt
4849

4950
.eslintcache
5051

51-
.history
52+
.history

fixtures/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const processAsync = async (
1818
processFunc: (
1919
resolver: (value: unknown) => void,
2020
reject: (value: unknown) => void,
21+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
2122
) => Promise<unknown> | unknown,
2223
) =>
2324
new Promise((resolve, reject) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"typedoc-plugin-markdown": "^3.17.0",
138138
"typedoc-plugin-mdn-links": "^2.0.0",
139139
"typedoc-plugin-merge-modules": "^5.1.0",
140-
"typescript": "^4.7.4",
140+
"typescript": "^5.5.4",
141141
"utf-8-validate": "^5.0.9",
142142
"web3-hardhat-plugin": "^1.0.0",
143143
"webpack": "^5.73.0",

packages/web3-account-abstraction/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"jest-extended": "^3.0.1",
5454
"prettier": "^2.7.1",
5555
"ts-jest": "^29.1.1",
56-
"typescript": "^4.7.4"
56+
"typescript": "^5.5.4"
5757
},
5858
"dependencies": {
5959
"web3-core": "^4.7.0",

packages/web3-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@
6868
"jest-when": "^3.5.1",
6969
"prettier": "^2.7.1",
7070
"ts-jest": "^29.1.1",
71-
"typescript": "^4.7.4"
71+
"typescript": "^5.5.4"
7272
}
7373
}

packages/web3-core/src/web3_subscription_manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export class Web3SubscriptionManager<
163163
const subscription = new Klass(args ?? undefined, {
164164
subscriptionManager: this as Web3SubscriptionManager<API, RegisteredSubs>,
165165
returnFormat,
166+
// eslint.disable-next-line @typescript-eslint/no-unsafe-any
166167
} as any) as InstanceType<RegisteredSubs[T]>;
167168

168169
await this.addSubscription(subscription);

packages/web3-core/test/unit/web3_promi_event.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('Web3PromiEvent', () => {
134134
});
135135

136136
const f = jest.fn();
137-
p.finally(f);
137+
await p.finally(f);
138138
await p;
139139
expect(f).toHaveBeenCalled();
140140
});

packages/web3-errors/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@
5555
"jest-extended": "^3.0.1",
5656
"prettier": "^2.7.1",
5757
"ts-jest": "^29.1.1",
58-
"typescript": "^4.7.4"
58+
"typescript": "^5.5.4"
5959
}
6060
}

packages/web3-errors/src/errors/contract_errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export class Eip838ExecutionError extends Web3ContractError {
150150
super(error.message || 'Error');
151151

152152
this.name = ('name' in error && error.name) || this.constructor.name;
153+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
153154
this.stack = ('stack' in error && error.stack) || undefined;
154155
this.code = error.code;
155156

packages/web3-eth-abi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@
6363
"jest-when": "^3.5.1",
6464
"prettier": "^2.7.1",
6565
"ts-jest": "^29.1.1",
66-
"typescript": "^4.7.4"
66+
"typescript": "^5.5.4"
6767
}
6868
}

packages/web3-eth-abi/src/coders/encode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function inferParamsAbi(params: unknown[]): ReadonlyArray<AbiParameter> {
4444
} as AbiParameter);
4545
} else {
4646
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
47-
abi.push({ type: toHex(param as any, true) } as AbiParameter);
47+
abi.push({ type: toHex(param as object, true) } as AbiParameter);
4848
}
4949
});
5050
return abi;

packages/web3-eth-abi/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export const flattenTypes = (
253253
* returns a string
254254
*/
255255
export const jsonInterfaceMethodToString = (json: AbiFragment): string => {
256+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
256257
if (isAbiErrorFragment(json) || isAbiEventFragment(json) || isAbiFunctionFragment(json)) {
257258
if (json.name?.includes('(')) {
258259
return json.name;

packages/web3-eth-accounts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"jest-when": "^3.5.1",
5555
"prettier": "^2.7.1",
5656
"ts-jest": "^29.1.1",
57-
"typescript": "^4.7.4",
57+
"typescript": "^5.5.4",
5858
"web3-providers-ipc": "^4.0.7"
5959
},
6060
"dependencies": {

packages/web3-eth-accounts/src/common/common.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export class Common extends EventEmitter {
190190
* @returns Common
191191
*/
192192
public static fromGethGenesis(
193+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
193194
genesisJson: any,
194195
{ chain, eips, genesisHash, hardfork, mergeForkIdPostMerge }: GethConfigOpts,
195196
): Common {
@@ -811,9 +812,9 @@ export class Common extends EventEmitter {
811812
*/
812813
// eslint-disable-next-line @typescript-eslint/ban-types
813814
public nextHardforkBlockOrTimestamp(_hardfork?: string | Hardfork): bigint | null {
814-
const hardfork = _hardfork ?? this._hardfork;
815+
const hardfork = (_hardfork as Hardfork) ?? this._hardfork;
815816
const hfs = this.hardforks();
816-
let hfIndex = hfs.findIndex(hf => hf.name === hardfork);
817+
let hfIndex = hfs.findIndex(hf => (hf.name as Hardfork) === hardfork);
817818
// If the current hardfork is merge, go one behind as merge hf is not part of these
818819
// calcs even if the merge hf block is set
819820
if (hardfork === Hardfork.Merge) {
@@ -842,7 +843,7 @@ export class Common extends EventEmitter {
842843
: // eslint-disable-next-line no-null/no-null
843844
null;
844845
return (
845-
hf.name !== Hardfork.Merge &&
846+
(hf.name as Hardfork) !== Hardfork.Merge &&
846847
// eslint-disable-next-line no-null/no-null
847848
hfTimeOrBlock !== null &&
848849
hfTimeOrBlock !== undefined &&
@@ -873,7 +874,7 @@ export class Common extends EventEmitter {
873874
*/
874875
// eslint-disable-next-line @typescript-eslint/ban-types
875876
public nextHardforkBlock(_hardfork?: string | Hardfork): bigint | null {
876-
const hardfork = _hardfork ?? this._hardfork;
877+
const hardfork = (_hardfork as Hardfork) ?? this._hardfork;
877878
let hfBlock = this.hardforkBlock(hardfork);
878879
// If this is a merge hardfork with block not set, then we fallback to previous hardfork
879880
// to find the nextHardforkBlock
@@ -905,7 +906,7 @@ export class Common extends EventEmitter {
905906
);
906907
// TypeScript can't seem to follow that the hfBlock is not null at this point
907908
// eslint-disable-next-line no-null/no-null
908-
return block > hfBlock! && acc === null ? block : acc;
909+
return block > hfBlock && acc === null ? block : acc;
909910
// eslint-disable-next-line no-null/no-null
910911
}, null);
911912
return nextHfBlock;
@@ -951,7 +952,7 @@ export class Common extends EventEmitter {
951952
typeof blockOrTime === 'number' &&
952953
blockOrTime !== 0 &&
953954
blockOrTime !== prevBlockOrTime &&
954-
name !== Hardfork.Merge
955+
(name as Hardfork) !== Hardfork.Merge
955956
) {
956957
const hfBlockUint8Array = hexToBytes(blockOrTime.toString(16).padStart(16, '0'));
957958
hfUint8Array = uint8ArrayConcat(hfUint8Array, hfBlockUint8Array);

packages/web3-eth-accounts/src/common/utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const intToHex = function (i: number) {
7171
* before merge like in kiln genesis
7272
* @returns genesis parameters in a `CommonOpts` compliant object
7373
*/
74+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7475
function parseGethParams(json: any, mergeForkIdPostMerge = true) {
7576
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
7677
const {
@@ -83,6 +84,7 @@ function parseGethParams(json: any, mergeForkIdPostMerge = true) {
8384
baseFeePerGas,
8485
}: {
8586
name: string;
87+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8688
config: any;
8789
difficulty: string;
8890
mixHash: string;
@@ -194,7 +196,7 @@ function parseGethParams(json: any, mergeForkIdPostMerge = true) {
194196
}, {});
195197
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
196198
const configHardforkNames = Object.keys(config).filter(
197-
// eslint-disable-next-line no-null/no-null, @typescript-eslint/no-unsafe-member-access
199+
// eslint-disable-next-line no-null/no-null, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/prefer-optional-chain
198200
key => forkMapRev[key] !== undefined && config[key] !== undefined && config[key] !== null,
199201
);
200202

@@ -250,7 +252,7 @@ function parseGethParams(json: any, mergeForkIdPostMerge = true) {
250252
// Merge hardfork has to be placed before first hardfork that is dependent on merge
251253
const postMergeIndex = params.hardforks.findIndex(
252254
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
253-
(hf: any) => forkMap[hf.name]?.postMerge === true,
255+
hf => forkMap[hf.name]?.postMerge === true,
254256
);
255257
if (postMergeIndex !== -1) {
256258
params.hardforks.splice(postMergeIndex, 0, mergeConfig as unknown as ConfigHardfork);
@@ -272,6 +274,7 @@ function parseGethParams(json: any, mergeForkIdPostMerge = true) {
272274
* @param name optional chain name
273275
* @returns parsed params
274276
*/
277+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
275278
export function parseGethGenesis(json: any, name?: string, mergeForkIdPostMerge?: boolean) {
276279
try {
277280
if (['config', 'difficulty', 'gasLimit', 'alloc'].some(field => !(field in json))) {
@@ -282,9 +285,9 @@ export function parseGethGenesis(json: any, name?: string, mergeForkIdPostMerge?
282285
json.name = name;
283286
}
284287
return parseGethParams(json, mergeForkIdPostMerge);
285-
} catch (e: any) {
288+
} catch (e) {
286289
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
287-
throw new Error(`Error parsing parameters file: ${e.message}`);
290+
throw new Error(`Error parsing parameters file: ${(e as { message: string }).message}`);
288291
}
289292
}
290293

packages/web3-eth-accounts/src/tx/baseTransaction.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export abstract class BaseTransaction<TransactionObject> {
307307
// Main signature verification is done in `getSenderPublicKey()`
308308
const publicKey = this.getSenderPublicKey();
309309
return unpadUint8Array(publicKey).length !== 0;
310-
} catch (e: any) {
310+
} catch (e) {
311311
return false;
312312
}
313313
}
@@ -510,6 +510,7 @@ export abstract class BaseTransaction<TransactionObject> {
510510
}
511511
}
512512

513+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
513514
protected static _validateNotArray(values: { [key: string]: any }) {
514515
const txDataKeys = [
515516
'nonce',
@@ -556,19 +557,19 @@ export abstract class BaseTransaction<TransactionObject> {
556557
let hash = '';
557558
try {
558559
hash = this.isSigned() ? bytesToHex(this.hash()) : 'not available (unsigned)';
559-
} catch (e: any) {
560+
} catch (e) {
560561
hash = 'error';
561562
}
562563
let isSigned = '';
563564
try {
564565
isSigned = this.isSigned().toString();
565-
} catch (e: any) {
566+
} catch (e) {
566567
hash = 'error';
567568
}
568569
let hf = '';
569570
try {
570571
hf = this.common.hardfork();
571-
} catch (e: any) {
572+
} catch (e) {
572573
hf = 'error';
573574
}
574575

@@ -603,15 +604,16 @@ export abstract class BaseTransaction<TransactionObject> {
603604
serialized: Uint8Array,
604605
// @ts-expect-error unused variable
605606
opts: TxOptions = {},
606-
// eslint-disable-next-line @typescript-eslint/no-empty-function
607+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
607608
): any {}
608609

609610
// eslint-disable-next-line @typescript-eslint/no-explicit-any
610611
public static fromTxData(
611612
// @ts-expect-error unused variable
613+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
612614
txData: any,
613615
// @ts-expect-error unused variable
614616
opts: TxOptions = {},
615-
// eslint-disable-next-line @typescript-eslint/no-empty-function
617+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any
616618
): any {}
617619
}

packages/web3-eth-accounts/src/tx/eip1559Transaction.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ export class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMarketEIP155
104104
throw new Error('Invalid serialized tx input: must be array');
105105
}
106106
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
107-
return FeeMarketEIP1559Transaction.fromValuesArray(values as any, opts);
107+
return FeeMarketEIP1559Transaction.fromValuesArray(
108+
values as FeeMarketEIP1559ValuesArray,
109+
opts,
110+
);
108111
}
109112

110113
/**
@@ -379,7 +382,7 @@ export class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMarketEIP155
379382
bigIntToUnpaddedUint8Array(r!),
380383
bigIntToUnpaddedUint8Array(s!),
381384
);
382-
} catch (e: any) {
385+
} catch (e) {
383386
const msg = this._errorMsg('Invalid Signature');
384387
throw new Error(msg);
385388
}

packages/web3-eth-accounts/src/tx/eip2930Transaction.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ export class AccessListEIP2930Transaction extends BaseTransaction<AccessListEIP2
103103
throw new Error('Invalid serialized tx input: must be array');
104104
}
105105
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
106-
return AccessListEIP2930Transaction.fromValuesArray(values as any, opts);
106+
return AccessListEIP2930Transaction.fromValuesArray(
107+
values as AccessListEIP2930ValuesArray,
108+
opts,
109+
);
107110
}
108111

109112
/**
@@ -337,7 +340,7 @@ export class AccessListEIP2930Transaction extends BaseTransaction<AccessListEIP2
337340
bigIntToUnpaddedUint8Array(r!),
338341
bigIntToUnpaddedUint8Array(s!),
339342
);
340-
} catch (e: any) {
343+
} catch (e) {
341344
const msg = this._errorMsg('Invalid Signature');
342345
throw new Error(msg);
343346
}

packages/web3-eth-accounts/src/tx/legacyTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class Transaction extends BaseTransaction<Transaction> {
322322
? this.common.chainId()
323323
: undefined,
324324
);
325-
} catch (e: any) {
325+
} catch (e) {
326326
const msg = this._errorMsg('Invalid Signature');
327327
throw new Error(msg);
328328
}

packages/web3-eth-accounts/src/tx/transactionFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const extraTxTypes: Map<Numbers, typeof BaseTransaction<unknown>> = new Map();
3636
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
3737
export class TransactionFactory {
3838
// It is not possible to instantiate a TransactionFactory object.
39-
// eslint-disable-next-line @typescript-eslint/no-empty-function, no-useless-constructor
39+
// eslint-disable-next-line no-useless-constructor, @typescript-eslint/no-empty-function
4040
private constructor() {}
4141

4242
public static typeToInt(txType: Numbers) {

packages/web3-eth-accounts/src/tx/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export interface FeeMarketEIP1559TxData extends AccessListEIP2930TxData {
206206
* The transaction's gas price, inherited from {@link Transaction}. This property is not used for EIP1559
207207
* transactions and should always be undefined for this specific transaction type.
208208
*/
209-
// eslint-disable-next-line @typescript-eslint/ban-types
209+
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-redundant-type-constituents
210210
gasPrice?: never | null;
211211
/**
212212
* The maximum inclusion fee per gas (this fee is given to the miner)

packages/web3-eth-accounts/src/tx/utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const verifyAccessList = (accessList: AccessListUint8Array) => {
8787
const address = accessListItem[0];
8888
const storageSlots = accessListItem[1];
8989
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/consistent-type-assertions
90-
if ((<any>accessListItem)[2] !== undefined) {
90+
if ((<Array<unknown>>accessListItem)[2] !== undefined) {
9191
throw new Error(
9292
'Access list item cannot have 3 elements. It can only have an address, and an array of storage slots.',
9393
);
@@ -115,13 +115,12 @@ export const getAccessListJSON = (
115115
const accessListJSON: { address: HexString; storageKeys: HexString[] }[] = [];
116116
// eslint-disable-next-line @typescript-eslint/prefer-for-of
117117
for (let index = 0; index < accessList.length; index += 1) {
118-
const item: any = accessList[index];
118+
const item = accessList[index];
119119
const JSONItem: { address: HexString; storageKeys: HexString[] } = {
120-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/consistent-type-assertions
121-
address: bytesToHex(setLengthLeft(<Uint8Array>item[0], 20)),
120+
address: bytesToHex(setLengthLeft(item[0], 20)),
122121
storageKeys: [],
123122
};
124-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/prefer-optional-chain
123+
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
125124
const storageSlots: Uint8Array[] = item && item[1];
126125
// eslint-disable-next-line @typescript-eslint/prefer-for-of
127126
for (let slot = 0; slot < storageSlots.length; slot += 1) {

packages/web3-eth-accounts/test/unit/common/hardforks.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ describe('[Common]: Hardfork logic', () => {
263263
c = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Shanghai });
264264
// unschedule shanghai on it to test
265265
c.hardforks()
266-
.filter(hf => hf.name === Hardfork.Shanghai)
266+
.filter(hf => (hf.name as Hardfork) === Hardfork.Shanghai)
267267
// eslint-disable-next-line array-callback-return
268268
.map(hf => {
269269
// eslint-disable-next-line no-null/no-null, no-param-reassign

packages/web3-eth-accounts/test/unit/common/mergePOS.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ describe('[Common]: Merge/POS specific logic', () => {
247247
it('should throw if encounters a double ttd hardfork specification', () => {
248248
const c = new Common({ chain: Chain.Sepolia });
249249
// Add the ttd to mergeForkIdTransition which occurs post merge in sepolia
250-
c.hardforks().filter(hf => hf.name === 'mergeForkIdTransition')[0]!['ttd'] =
250+
c.hardforks().filter(hf => hf.name === 'mergeForkIdTransition')[0]['ttd'] =
251251
'17000000000000000';
252252
expect(() => {
253253
c.setHardforkByBlockNumber(1735371);

0 commit comments

Comments
 (0)