From 5e063580431ac62cdb8c009eea93ffad2b64e797 Mon Sep 17 00:00:00 2001 From: tmm Date: Mon, 30 Mar 2026 11:43:33 -0400 Subject: [PATCH] chore: fix ts --- scripts/tsconfig.json | 2 +- site/tsconfig.json | 3 +- src/actions/public/getFilterChanges.test-d.ts | 38 +++++++++---------- src/actions/public/getFilterChanges.test.ts | 5 ++- src/actions/public/getFilterLogs.test-d.ts | 24 ++++++------ src/actions/public/getFilterLogs.test.ts | 5 ++- src/actions/public/getLogs.test-d.ts | 5 ++- src/actions/public/getLogs.test.ts | 3 +- src/actions/wallet/waitForCallsStatus.ts | 2 +- src/tsconfig.json | 3 +- src/types/contract.test-d.ts | 23 +++++++---- src/utils/abi/decodeEventLog.test-d.ts | 5 ++- test/src/typeUtils.ts | 27 +++++++++++++ test/tsconfig.json | 2 +- 14 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 test/src/typeUtils.ts diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 8eb6dcaad6..8fe5a5d85e 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -4,6 +4,6 @@ "compilerOptions": { "composite": true, "noEmit": true, - "types": ["@types/bun"] + "types": ["@types/bun", "node"] } } diff --git a/site/tsconfig.json b/site/tsconfig.json index 508de51e7c..a11d31bbb0 100644 --- a/site/tsconfig.json +++ b/site/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "noEmit": true, "jsx": "react-jsx", - "resolveJsonModule": true + "resolveJsonModule": true, + "types": ["node"] }, "include": ["./**/*.ts", "./**/*.tsx"], "exclude": ["snippets"] diff --git a/src/actions/public/getFilterChanges.test-d.ts b/src/actions/public/getFilterChanges.test-d.ts index b0097100c7..329af13a1b 100644 --- a/src/actions/public/getFilterChanges.test-d.ts +++ b/src/actions/public/getFilterChanges.test-d.ts @@ -3,6 +3,7 @@ import { describe, expectTypeOf, test } from 'vitest' import { usdcContractConfig } from '~test/abis.js' import { anvilMainnet } from '~test/anvil.js' +import type { NormalizeType } from '~test/typeUtils.js' import type { Log } from '../../types/log.js' import type { Hash, Hex } from '../../types/misc.js' @@ -123,7 +124,7 @@ describe('createEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ owner?: Address spender?: Address foo?: Address @@ -174,7 +175,7 @@ describe('createEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ owner?: Address spender?: Address foo?: Address @@ -284,7 +285,7 @@ describe('createEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Transfer' | 'Approval'>() - expectTypeOf(logs[0].args).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | { from?: Address to?: Address @@ -297,9 +298,10 @@ describe('createEventFilter', () => { } >() - expectTypeOf( - logs[0].eventName === 'Transfer' && logs[0].args, - ).toEqualTypeOf< + const transferArgs = logs[0].eventName === 'Transfer' && logs[0].args + const approvalArgs = logs[0].eventName === 'Approval' && logs[0].args + + expectTypeOf>().toEqualTypeOf< | false | { from?: Address @@ -307,9 +309,7 @@ describe('createEventFilter', () => { value?: bigint } >() - expectTypeOf( - logs[0].eventName === 'Approval' && logs[0].args, - ).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | false | { owner?: Address @@ -459,7 +459,7 @@ describe('createContractEventFilter', () => { expectTypeOf(logs[0].eventName).toEqualTypeOf< 'Transfer' | 'Approval' | 'Foo' >() - expectTypeOf(logs[0].args).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | { from?: Address to?: Address @@ -479,9 +479,11 @@ describe('createContractEventFilter', () => { } >() - expectTypeOf( - logs[0].eventName === 'Transfer' && logs[0].args, - ).toEqualTypeOf< + const transferArgs = logs[0].eventName === 'Transfer' && logs[0].args + const approvalArgs = logs[0].eventName === 'Approval' && logs[0].args + const fooArgs = logs[0].eventName === 'Foo' && logs[0].args + + expectTypeOf>().toEqualTypeOf< | false | { from?: Address @@ -489,9 +491,7 @@ describe('createContractEventFilter', () => { value?: bigint } >() - expectTypeOf( - logs[0].eventName === 'Approval' && logs[0].args, - ).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | false | { owner?: Address @@ -499,7 +499,7 @@ describe('createContractEventFilter', () => { value?: bigint } >() - expectTypeOf(logs[0].eventName === 'Foo' && logs[0].args).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | false | { owner?: Address @@ -586,7 +586,7 @@ describe('createContractEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ owner?: Address spender?: Address foo?: Address @@ -639,7 +639,7 @@ describe('createContractEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ owner?: Address spender?: Address foo?: Address diff --git a/src/actions/public/getFilterChanges.test.ts b/src/actions/public/getFilterChanges.test.ts index e57883b6ba..516d87c52a 100644 --- a/src/actions/public/getFilterChanges.test.ts +++ b/src/actions/public/getFilterChanges.test.ts @@ -12,6 +12,7 @@ import { ERC20InvalidTransferEvent } from '~contracts/generated.js' import { usdcContractConfig } from '~test/abis.js' import { anvilMainnet } from '~test/anvil.js' import { accounts, address } from '~test/constants.js' +import type { NormalizeType } from '~test/typeUtils.js' import { deployErc20InvalidTransferEvent } from '~test/utils.js' import type { Log } from '../../types/log.js' import type { Hash } from '../../types/misc.js' @@ -711,7 +712,7 @@ describe('events', () => { Log[] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Transfer'>() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ from?: Address to?: Address value?: bigint @@ -882,7 +883,7 @@ describe('events', () => { expect(logs.length).toBe(1482) - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ from?: Address to?: Address value?: bigint diff --git a/src/actions/public/getFilterLogs.test-d.ts b/src/actions/public/getFilterLogs.test-d.ts index 0b252ed6ee..da41d3ec84 100644 --- a/src/actions/public/getFilterLogs.test-d.ts +++ b/src/actions/public/getFilterLogs.test-d.ts @@ -3,6 +3,7 @@ import { describe, expectTypeOf, test } from 'vitest' import { usdcContractConfig } from '~test/abis.js' import { anvilMainnet } from '~test/anvil.js' +import type { NormalizeType } from '~test/typeUtils.js' import type { Log } from '../../types/log.js' import type { Hash, Hex } from '../../types/misc.js' @@ -123,7 +124,7 @@ describe('createEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ owner?: Address spender?: Address foo?: Address @@ -174,7 +175,7 @@ describe('createEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ owner?: Address spender?: Address foo?: Address @@ -284,7 +285,7 @@ describe('createEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Transfer' | 'Approval'>() - expectTypeOf(logs[0].args).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | { from?: Address to?: Address @@ -297,9 +298,10 @@ describe('createEventFilter', () => { } >() - expectTypeOf( - logs[0].eventName === 'Transfer' && logs[0].args, - ).toEqualTypeOf< + const transferArgs = logs[0].eventName === 'Transfer' && logs[0].args + const approvalArgs = logs[0].eventName === 'Approval' && logs[0].args + + expectTypeOf>().toEqualTypeOf< | false | { from?: Address @@ -307,9 +309,7 @@ describe('createEventFilter', () => { value?: bigint } >() - expectTypeOf( - logs[0].eventName === 'Approval' && logs[0].args, - ).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | false | { owner?: Address @@ -459,7 +459,7 @@ describe('createContractEventFilter', () => { expectTypeOf(logs[0].eventName).toEqualTypeOf< 'Transfer' | 'Approval' | 'Foo' >() - expectTypeOf(logs[0].args).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | { from?: Address to?: Address @@ -555,7 +555,7 @@ describe('createContractEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ owner?: Address spender?: Address foo?: Address @@ -608,7 +608,7 @@ describe('createContractEventFilter', () => { [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Foo'>() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ owner?: Address spender?: Address foo?: Address diff --git a/src/actions/public/getFilterLogs.test.ts b/src/actions/public/getFilterLogs.test.ts index 450c88a82f..df2c24d078 100644 --- a/src/actions/public/getFilterLogs.test.ts +++ b/src/actions/public/getFilterLogs.test.ts @@ -12,6 +12,7 @@ import { ERC20InvalidTransferEvent } from '~contracts/generated.js' import { usdcContractConfig } from '~test/abis.js' import { anvilMainnet } from '~test/anvil.js' import { accounts, address } from '~test/constants.js' +import type { NormalizeType } from '~test/typeUtils.js' import { deployErc20InvalidTransferEvent } from '~test/utils.js' import type { Log } from '../../types/log.js' import { getAddress } from '../../utils/address/getAddress.js' @@ -170,7 +171,7 @@ describe('contract events', () => { >[] >() expectTypeOf(logs[0].eventName).toEqualTypeOf<'Transfer' | 'Approval'>() - expectTypeOf(logs[0].args).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | { from?: Address to?: Address @@ -759,7 +760,7 @@ describe('raw events', () => { expect(logs.length).toBe(1482) - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ from?: Address to?: Address value?: bigint diff --git a/src/actions/public/getLogs.test-d.ts b/src/actions/public/getLogs.test-d.ts index be69471d81..3ae62a8e36 100644 --- a/src/actions/public/getLogs.test-d.ts +++ b/src/actions/public/getLogs.test-d.ts @@ -2,6 +2,7 @@ import type { AbiEvent } from 'abitype' import { expectTypeOf, test } from 'vitest' import { anvilMainnet } from '~test/anvil.js' +import type { NormalizeType } from '~test/typeUtils.js' import type { Hash, Hex } from '../../types/misc.js' import { getLogs } from './getLogs.js' @@ -47,7 +48,7 @@ test('event: const assertion', async () => { expectTypeOf(logs[0].topics).toEqualTypeOf< [`0x${string}`, `0x${string}`, `0x${string}`] >() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ from?: `0x${string}` to?: `0x${string}` value?: bigint @@ -94,7 +95,7 @@ test('event: defined inline', async () => { expectTypeOf(logs[0].topics).toEqualTypeOf< [`0x${string}`, `0x${string}`, `0x${string}`] >() - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ from?: `0x${string}` to?: `0x${string}` value?: bigint diff --git a/src/actions/public/getLogs.test.ts b/src/actions/public/getLogs.test.ts index 85f68cf41f..9f4d78784a 100644 --- a/src/actions/public/getLogs.test.ts +++ b/src/actions/public/getLogs.test.ts @@ -11,6 +11,7 @@ import { ERC20InvalidTransferEvent } from '~contracts/generated.js' import { usdcContractConfig } from '~test/abis.js' import { anvilMainnet } from '~test/anvil.js' import { accounts, address } from '~test/constants.js' +import type { NormalizeType } from '~test/typeUtils.js' import { deployErc20InvalidTransferEvent } from '~test/utils.js' import type { Log } from '../../types/log.js' import { getAddress } from '../../utils/address/getAddress.js' @@ -304,7 +305,7 @@ describe('events', () => { ) expect(logs.length).toBe(1482) - expectTypeOf(logs[0].args).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ from?: `0x${string}` to?: `0x${string}` value?: bigint diff --git a/src/actions/wallet/waitForCallsStatus.ts b/src/actions/wallet/waitForCallsStatus.ts index 864d45ec49..63848d9a02 100644 --- a/src/actions/wallet/waitForCallsStatus.ts +++ b/src/actions/wallet/waitForCallsStatus.ts @@ -109,7 +109,7 @@ export async function waitForCallsStatus( const { promise, resolve, reject } = withResolvers() - let timer: Timer | undefined + let timer: ReturnType | undefined const unobserve = observe(observerId, { resolve, reject }, (emit) => { const unpoll = poll( diff --git a/src/tsconfig.json b/src/tsconfig.json index c111bb75ba..14186c3455 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -4,6 +4,7 @@ "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts", "./**/*.bench-d.ts"], "compilerOptions": { "composite": true, - "noEmit": true + "noEmit": true, + "types": ["node"] } } diff --git a/src/types/contract.test-d.ts b/src/types/contract.test-d.ts index bcc9d44bb2..25e269d98b 100644 --- a/src/types/contract.test-d.ts +++ b/src/types/contract.test-d.ts @@ -6,6 +6,7 @@ import { } from 'abitype' import type { seaportAbi } from 'abitype/abis' import { expectTypeOf, test } from 'vitest' +import type { NormalizeType } from '~test/typeUtils.js' import type { AbiEventParametersToPrimitiveTypes, @@ -213,22 +214,28 @@ test('GetEventArgs', () => { ], 'Transfer' > - expectTypeOf().toEqualTypeOf<{ - from?: `0x${string}` | `0x${string}`[] | null | undefined - to?: `0x${string}` | `0x${string}`[] | null | undefined - }>() + expectTypeOf().toEqualTypeOf< + `0x${string}` | `0x${string}`[] | null | undefined + >() + expectTypeOf().toEqualTypeOf< + `0x${string}` | `0x${string}`[] | null | undefined + >() }) test('GetValue', () => { // payable type Result = GetValue - expectTypeOf().toEqualTypeOf<{ value?: bigint }>() + expectTypeOf>().toEqualTypeOf<{ value?: bigint }>() // other - expectTypeOf>().toEqualTypeOf<{ + expectTypeOf< + NormalizeType> + >().toEqualTypeOf<{ value?: never }>() - expectTypeOf>().toEqualTypeOf<{ + expectTypeOf< + NormalizeType> + >().toEqualTypeOf<{ value?: never }>() @@ -347,7 +354,7 @@ test('AbiEventParametersToPrimitiveTypes', () => { Required: false } > - expectTypeOf().toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ foo?: string bar?: number }>() diff --git a/src/utils/abi/decodeEventLog.test-d.ts b/src/utils/abi/decodeEventLog.test-d.ts index 512a74f0b9..3823df5665 100644 --- a/src/utils/abi/decodeEventLog.test-d.ts +++ b/src/utils/abi/decodeEventLog.test-d.ts @@ -1,5 +1,6 @@ import type { Abi, Address } from 'abitype' import { expectTypeOf, test } from 'vitest' +import type { NormalizeType } from '~test/typeUtils.js' import { decodeEventLog } from './decodeEventLog.js' @@ -124,7 +125,7 @@ test('named (strict = false)', async () => { ], }) - expectTypeOf(event).toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ args: { from?: Address to?: Address @@ -342,7 +343,7 @@ test('unknown eventName (strict = false)', async () => { ], }) - expectTypeOf(event).toEqualTypeOf< + expectTypeOf>().toEqualTypeOf< | { args: { from?: Address diff --git a/test/src/typeUtils.ts b/test/src/typeUtils.ts new file mode 100644 index 0000000000..905ec67048 --- /dev/null +++ b/test/src/typeUtils.ts @@ -0,0 +1,27 @@ +import type { Prettify } from '../../src/types/utils.js' + +type NormalizeObject = Prettify< + { + [K in keyof T as [T[K]] extends [never] + ? never + : undefined extends T[K] + ? K + : never]?: NormalizeType> + } & { + [K in keyof T as [T[K]] extends [never] + ? never + : undefined extends T[K] + ? never + : K]: NormalizeType + } +> + +export type NormalizeType = T extends (...args: any) => any + ? T + : T extends readonly unknown[] + ? number extends T['length'] + ? readonly NormalizeType[] + : { [K in keyof T]: NormalizeType } + : T extends object + ? NormalizeObject + : T diff --git a/test/tsconfig.json b/test/tsconfig.json index c7853e5570..1c908c0f0e 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -5,7 +5,7 @@ "compilerOptions": { "composite": true, "noEmit": true, - "types": ["@types/bun"], + "types": ["@types/bun", "node"], "paths": { "~contracts/*": ["../contracts/*"], "~test/*": ["./src/*"],