Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update typescript version to 5 #7272

Open
wants to merge 20 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
013847a
fix some issues detected by typescript v5
Muhammad-Altabba Sep 19, 2024
1c9f150
upgrade typescript to v5
Muhammad-Altabba Sep 19, 2024
ade7ab6
Merge branch '4.x' into 7144-fix-typescript-version-issue
Muhammad-Altabba Sep 23, 2024
6d4c4ba
fix a type casting
Muhammad-Altabba Sep 23, 2024
5ad813a
Merge branch '4.x' into 7144-fix-typescript-version-issue
Muhammad-Altabba Sep 24, 2024
2b13128
Merge branch '4.x' into 7144-fix-typescript-version-issue
Muhammad-Altabba Sep 24, 2024
35ad780
decrease the minor version of typescript
Muhammad-Altabba Sep 25, 2024
c616709
Merge branch '4.x' into 7144-fix-typescript-version-issue
Muhammad-Altabba Sep 25, 2024
04da324
temp change the canary release to be published on feature branch
Muhammad-Altabba Sep 26, 2024
32c8cc8
Merge branch '4.x' into 7144-fix-typescript-version-issue
Muhammad-Altabba Sep 26, 2024
8c17262
revert a temp change
Muhammad-Altabba Sep 26, 2024
dea289d
Merge branch '4.x' into 7144-fix-typescript-version-issue
Muhammad-Altabba Nov 5, 2024
e28872a
update typescript version for web3-account-abstraction
Muhammad-Altabba Nov 5, 2024
e222a91
Merge branch '4.x' into 7144-fix-typescript-version-issue
Muhammad-Altabba Nov 20, 2024
f631502
delete un needed files
Muhammad-Altabba Nov 20, 2024
6b1f7a7
fix lint issues after the typescript version upgrade
Muhammad-Altabba Nov 20, 2024
0cbc23d
publish a canary version
Muhammad-Altabba Nov 21, 2024
4c55d98
tiny modifications
Muhammad-Altabba Nov 21, 2024
7109fb2
fix a lint ignore error
Muhammad-Altabba Nov 21, 2024
32ad76e
revert a temp change for the canary publish
Muhammad-Altabba Nov 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tmp
lib/
dist/
tsconfig.tsbuildinfo
tsconfig.types.tsbuildinfo

# Unsupported lock files
package-lock.json
Expand All @@ -48,4 +49,4 @@ benchmark-data.txt

.eslintcache

.history
.history
1 change: 1 addition & 0 deletions fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> | unknown,
) =>
new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
jdevcs marked this conversation as resolved.
Show resolved Hide resolved
"typescript": "^5.5.4",
"utf-8-validate": "^5.0.9",
"web3-hardhat-plugin": "^1.0.0",
"webpack": "^5.73.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-account-abstraction/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 1 addition & 0 deletions packages/web3-core/src/web3_subscription_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class Web3SubscriptionManager<
const subscription = new Klass(args ?? undefined, {
subscriptionManager: this as Web3SubscriptionManager<API, RegisteredSubs>,
returnFormat,
// eslint.disable-next-line @typescript-eslint/no-unsafe-any
} as any) as InstanceType<RegisteredSubs[T]>;

await this.addSubscription(subscription);
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core/test/unit/web3_promi_event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('Web3PromiEvent', () => {
});

const f = jest.fn();
p.finally(f);
await p.finally(f);
await p;
expect(f).toHaveBeenCalled();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 1 addition & 0 deletions packages/web3-errors/src/errors/contract_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/src/coders/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function inferParamsAbi(params: unknown[]): ReadonlyArray<AbiParameter> {
} 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;
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth-abi/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 7 additions & 6 deletions packages/web3-eth-accounts/src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions packages/web3-eth-accounts/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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,
);

Expand Down Expand Up @@ -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);
Expand All @@ -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))) {
Expand All @@ -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}`);
}
}

Expand Down
14 changes: 8 additions & 6 deletions packages/web3-eth-accounts/src/tx/baseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export abstract class BaseTransaction<TransactionObject> {
// Main signature verification is done in `getSenderPublicKey()`
const publicKey = this.getSenderPublicKey();
return unpadUint8Array(publicKey).length !== 0;
} catch (e: any) {
} catch (e) {
return false;
}
}
Expand Down Expand Up @@ -510,6 +510,7 @@ export abstract class BaseTransaction<TransactionObject> {
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected static _validateNotArray(values: { [key: string]: any }) {
const txDataKeys = [
'nonce',
Expand Down Expand Up @@ -556,19 +557,19 @@ export abstract class BaseTransaction<TransactionObject> {
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';
}

Expand Down Expand Up @@ -603,15 +604,16 @@ export abstract class BaseTransaction<TransactionObject> {
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 {}
}
7 changes: 5 additions & 2 deletions packages/web3-eth-accounts/src/tx/eip1559Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ export class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMarketEIP155
throw new Error('Invalid serialized tx input: must be array');
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return FeeMarketEIP1559Transaction.fromValuesArray(values as any, opts);
return FeeMarketEIP1559Transaction.fromValuesArray(
values as FeeMarketEIP1559ValuesArray,
opts,
);
}

/**
Expand Down Expand Up @@ -379,7 +382,7 @@ export class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMarketEIP155
bigIntToUnpaddedUint8Array(r!),
bigIntToUnpaddedUint8Array(s!),
);
} catch (e: any) {
} catch (e) {
const msg = this._errorMsg('Invalid Signature');
throw new Error(msg);
}
Expand Down
7 changes: 5 additions & 2 deletions packages/web3-eth-accounts/src/tx/eip2930Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ export class AccessListEIP2930Transaction extends BaseTransaction<AccessListEIP2
throw new Error('Invalid serialized tx input: must be array');
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return AccessListEIP2930Transaction.fromValuesArray(values as any, opts);
return AccessListEIP2930Transaction.fromValuesArray(
values as AccessListEIP2930ValuesArray,
opts,
);
}

/**
Expand Down Expand Up @@ -337,7 +340,7 @@ export class AccessListEIP2930Transaction extends BaseTransaction<AccessListEIP2
bigIntToUnpaddedUint8Array(r!),
bigIntToUnpaddedUint8Array(s!),
);
} catch (e: any) {
} catch (e) {
const msg = this._errorMsg('Invalid Signature');
throw new Error(msg);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/tx/legacyTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class Transaction extends BaseTransaction<Transaction> {
? this.common.chainId()
: undefined,
);
} catch (e: any) {
} catch (e) {
const msg = this._errorMsg('Invalid Signature');
throw new Error(msg);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/tx/transactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const extraTxTypes: Map<Numbers, typeof BaseTransaction<unknown>> = 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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/tx/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions packages/web3-eth-accounts/src/tx/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ((<any>accessListItem)[2] !== undefined) {
if ((<Array<unknown>>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.',
);
Expand Down Expand Up @@ -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(<Uint8Array>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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Loading