Skip to content

Commit

Permalink
Revert "refactor: use const type parameters" (#1025)
Browse files Browse the repository at this point in the history
Revert "refactor: use const type parameters (#1017)"

This reverts commit 2bbe907.
  • Loading branch information
tmm authored Aug 14, 2023
1 parent 2bbe907 commit c727ef2
Show file tree
Hide file tree
Showing 56 changed files with 268 additions and 392 deletions.
5 changes: 0 additions & 5 deletions .changeset/thin-mirrors-repeat.md

This file was deleted.

5 changes: 0 additions & 5 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ jobs:
needs: lint
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
typescript-version: ['5.0.4', 'latest']

steps:
- name: Clone repository
Expand All @@ -59,8 +56,6 @@ jobs:
- name: Install dependencies
uses: ./.github/actions/install-dependencies

- run: pnpm add -D -w typescript@${{ matrix.typescript-version }}

- name: Build contracts
shell: bash
run: pnpm contracts:build
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
"rome": "~12.1.3",
"simple-git-hooks": "^2.8.1",
"size-limit": "^8.2.4",
"typescript": "5.0.4",
"typescript": "^5.0.4",
"vite": "^4.4.2",
"vitest": "~0.30.1"
},
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/_test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* c8 ignore start */
import type { Abi } from 'abitype'

import { type RequestListener, createServer } from 'http'
import type { AddressInfo } from 'net'

import erc20InvalidTransferEvent from '../../contracts/out/ERC20InvalidTransferEvent.sol/ERC20InvalidTransferEvent.json'
import ensAvatarTokenUri from '../../contracts/out/EnsAvatarTokenUri.sol/EnsAvatarTokenUri.json'
import errorsExample from '../../contracts/out/ErrorsExample.sol/ErrorsExample.json'
Expand Down Expand Up @@ -47,6 +44,8 @@ import {
errorsExampleABI,
offchainLookupExampleABI,
} from './generated.js'
import { type RequestListener, createServer } from 'http'
import type { AddressInfo } from 'net'

export const anvilChain = {
...localhost,
Expand Down Expand Up @@ -195,7 +194,7 @@ export function createHttpServer(
})
}

export async function deploy<const TAbi extends Abi | readonly unknown[]>(
export async function deploy<TAbi extends Abi | readonly unknown[],>(
args: DeployContractParameters<
TAbi,
typeof walletClientWithAccount['chain'],
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type CustomSource = {
: Hash
>
signTypedData: <
const TTypedData extends TypedData | { [key: string]: unknown },
TTypedData extends TypedData | { [key: string]: unknown },
TPrimaryType extends string = string,
>(
typedData: TypedDataDefinition<TTypedData, TPrimaryType>,
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/utils/signTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type SignTypedDataReturnType = Hex
* @returns The signature.
*/
export async function signTypedData<
const TTypedData extends TypedData | { [key: string]: unknown },
TTypedData extends TypedData | { [key: string]: unknown },
TPrimaryType extends string = string,
>({
privateKey,
Expand Down
7 changes: 3 additions & 4 deletions src/actions/getContract.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ test('empty abi', () => {
walletClient,
})
expectTypeOf<keyof typeof contract>().toEqualTypeOf<'address' | 'abi'>()
expectTypeOf(contract.abi).toEqualTypeOf<readonly []>()
expectTypeOf(contract.abi).toEqualTypeOf<[]>()
expectTypeOf(
contract.address,
).toEqualTypeOf<'0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'>()
Expand Down Expand Up @@ -741,13 +741,12 @@ test('argument permutations', async () => {
})
expectTypeOf(createEventFilter_1.eventName)
.toEqualTypeOf<'WithIndexedNamedInputs'>
expectTypeOf(createEventFilter_1.args.x).toEqualTypeOf<'foo'>()
expectTypeOf(createEventFilter_1.args.y).toEqualTypeOf<null>()
expectTypeOf(createEventFilter_1.args).toEqualTypeOf<{ x: 'foo'; y: null }>()
const createEventFilter_2 =
await contract.createEventFilter.WithIndexedUnnamedInputs(['foo'])
expectTypeOf(createEventFilter_2.eventName)
.toEqualTypeOf<'WithIndexedUnnamedInputs'>
expectTypeOf(createEventFilter_2.args[0]).toEqualTypeOf<'foo'>()
expectTypeOf(createEventFilter_2.args).toEqualTypeOf<['foo']>()

const createEventFilter_loose =
await contract.createEventFilter.WithMixedNamedInputs({
Expand Down
11 changes: 5 additions & 6 deletions src/actions/getContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ExtractAbiEventNames,
ExtractAbiFunction,
ExtractAbiFunctionNames,
Narrow,
} from 'abitype'

import type { Account } from '../accounts/types.js'
Expand Down Expand Up @@ -71,7 +72,7 @@ export type GetContractParameters<
TAddress extends Address = Address,
> = {
/** Contract ABI */
abi: TAbi
abi: Narrow<TAbi>
/** Contract address */
address: TAddress
/**
Expand Down Expand Up @@ -384,7 +385,7 @@ export type GetContractReturnType<
export function getContract<
TTransport extends Transport,
TAddress extends Address,
const TAbi extends Abi | readonly unknown[],
TAbi extends Abi | readonly unknown[],
TChain extends Chain | undefined = Chain | undefined,
TAccount extends Account | undefined = Account | undefined,
TPublicClient extends PublicClient<TTransport, TChain> | undefined =
Expand Down Expand Up @@ -864,15 +865,13 @@ type GetEventFilter<
IndexedInputs = Extract<TAbiEvent['inputs'][number], { indexed: true }>,
> = Narrowable extends true
? <
const TArgs extends
| MaybeExtractEventArgsFromAbi<TAbi, TEventName>
| undefined,
TArgs extends MaybeExtractEventArgsFromAbi<TAbi, TEventName> | undefined,
TStrict extends boolean | undefined = undefined,
>(
...parameters: IsNever<IndexedInputs> extends true
? [options?: Options & { strict?: TStrict }]
: [
args: Args | (Args extends TArgs ? Readonly<TArgs> : never),
args: Args | (Args extends Narrow<TArgs> ? Narrow<TArgs> : never),
options?: Options & { strict?: TStrict },
]
) => Promise<
Expand Down
6 changes: 3 additions & 3 deletions src/actions/public/createContractEventFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Abi, Address } from 'abitype'
import type { Abi, Address, Narrow } from 'abitype'

import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
Expand Down Expand Up @@ -28,7 +28,7 @@ export type CreateContractEventFilterParameters<
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
> = {
address?: Address | Address[]
abi: TAbi
abi: Narrow<TAbi>
eventName?: InferEventName<TAbi, TEventName>
fromBlock?: TFromBlock | BlockNumber | BlockTag
/**
Expand Down Expand Up @@ -87,7 +87,7 @@ export type CreateContractEventFilterReturnType<
*/
export async function createContractEventFilter<
TChain extends Chain | undefined,
const TAbi extends Abi | readonly unknown[],
TAbi extends Abi | readonly unknown[],
TEventName extends string | undefined,
TArgs extends MaybeExtractEventArgsFromAbi<TAbi, TEventName> | undefined,
TStrict extends boolean | undefined = undefined,
Expand Down
12 changes: 6 additions & 6 deletions src/actions/public/createEventFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AbiEvent, Address } from 'abitype'
import type { AbiEvent, Address, Narrow } from 'abitype'

import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
Expand Down Expand Up @@ -44,7 +44,7 @@ export type CreateEventFilterParameters<
args:
| TEventFilterArgs
| (_Args extends TEventFilterArgs ? _Args : never)
event: TAbiEvent
event: Narrow<TAbiEvent>
events?: never
/**
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
Expand All @@ -54,7 +54,7 @@ export type CreateEventFilterParameters<
}
| {
args?: never
event?: TAbiEvent
event?: Narrow<TAbiEvent>
events?: never
/**
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
Expand All @@ -65,7 +65,7 @@ export type CreateEventFilterParameters<
| {
args?: never
event?: never
events: TAbiEvents
events: Narrow<TAbiEvents>
/**
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
* @default false
Expand Down Expand Up @@ -127,8 +127,8 @@ export type CreateEventFilterReturnType<
*/
export async function createEventFilter<
TChain extends Chain | undefined,
const TAbiEvent extends AbiEvent | undefined = undefined,
const TAbiEvents extends
TAbiEvent extends AbiEvent | undefined = undefined,
TAbiEvents extends
| readonly AbiEvent[]
| readonly unknown[]
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/estimateContractGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export type EstimateContractGasReturnType = bigint
* })
*/
export async function estimateContractGas<
const TAbi extends Abi | readonly unknown[],
TAbi extends Abi | readonly unknown[],
TFunctionName extends string,
TChain extends Chain | undefined,
TAccount extends Account | undefined = undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/actions/public/getFilterChanges.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ describe('createEventFilter', () => {
const logs = await getFilterChanges(publicClient, {
filter,
})
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf(logs[0]['args']).toEqualTypeOf<{
from: `0x${string}`
to: `0x${string}`
value: bigint
Expand Down Expand Up @@ -396,7 +396,7 @@ describe('createEventFilter', () => {
const logs = await getFilterChanges(publicClient, {
filter,
})
expectTypeOf(logs[0].args).toEqualTypeOf<
expectTypeOf(logs[0]['args']).toEqualTypeOf<
readonly [`0x${string}`, `0x${string}`, bigint, string, string]
>()
})
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/getFilterChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function getFilterChanges<
TTransport extends Transport,
TChain extends Chain | undefined,
TFilterType extends FilterType,
const TAbi extends Abi | readonly unknown[] | undefined,
TAbi extends Abi | readonly unknown[] | undefined,
TEventName extends string | undefined,
TStrict extends boolean | undefined = undefined,
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
Expand Down
6 changes: 3 additions & 3 deletions src/actions/public/getFilterLogs.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Abi, AbiEvent, Address } from 'abitype'
import { describe, expectTypeOf, test } from 'vitest'

import { usdcContractConfig } from '../../_test/abis.js'
Expand All @@ -8,6 +7,7 @@ import type { Hash, Hex } from '../../types/misc.js'
import { createContractEventFilter } from './createContractEventFilter.js'
import { createEventFilter } from './createEventFilter.js'
import { getFilterLogs } from './getFilterLogs.js'
import type { Abi, AbiEvent, Address } from 'abitype'

describe('createEventFilter', () => {
test('default', async () => {
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('createEventFilter', () => {
const logs = await getFilterLogs(publicClient, {
filter,
})
expectTypeOf(logs[0].args).toEqualTypeOf<{
expectTypeOf(logs[0]['args']).toEqualTypeOf<{
from: `0x${string}`
to: `0x${string}`
value: bigint
Expand Down Expand Up @@ -396,7 +396,7 @@ describe('createEventFilter', () => {
const logs = await getFilterLogs(publicClient, {
filter,
})
expectTypeOf(logs[0].args).toEqualTypeOf<
expectTypeOf(logs[0]['args']).toEqualTypeOf<
readonly [`0x${string}`, `0x${string}`, bigint, string, string]
>()
})
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/getFilterLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export type GetFilterLogsReturnType<
*/
export async function getFilterLogs<
TChain extends Chain | undefined,
const TAbi extends Abi | readonly unknown[] | undefined,
TAbi extends Abi | readonly unknown[] | undefined,
TEventName extends string | undefined,
TStrict extends boolean | undefined = undefined,
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
Expand Down
10 changes: 5 additions & 5 deletions src/actions/public/getLogs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Abi, AbiEvent, Address } from 'abitype'
import type { Abi, AbiEvent, Address, Narrow } from 'abitype'

import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
Expand Down Expand Up @@ -38,7 +38,7 @@ export type GetLogsParameters<
address?: Address | Address[]
} & (
| {
event: TAbiEvent
event: Narrow<TAbiEvent>
events?: never
args?: MaybeExtractEventArgsFromAbi<TAbiEvents, _EventName>
/**
Expand All @@ -49,7 +49,7 @@ export type GetLogsParameters<
}
| {
event?: never
events: TAbiEvents
events: Narrow<TAbiEvents>
args?: never
/**
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
Expand Down Expand Up @@ -119,8 +119,8 @@ export type GetLogsReturnType<
*/
export async function getLogs<
TChain extends Chain | undefined,
const TAbiEvent extends AbiEvent | undefined = undefined,
const TAbiEvents extends
TAbiEvent extends AbiEvent | undefined = undefined,
TAbiEvents extends
| readonly AbiEvent[]
| readonly unknown[]
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
Expand Down
Loading

1 comment on commit c727ef2

@vercel
Copy link

@vercel vercel bot commented on c727ef2 Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.