Skip to content

Commit

Permalink
Add internal alias for Pretty type
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree committed Dec 18, 2024
1 parent 35b3d1c commit acea457
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/drift/src/client/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ import { ClientCache } from "src/client/cache/ClientCache";
import { MethodInterceptor } from "src/client/hooks/MethodInterceptor";
import { DriftError } from "src/error/DriftError";
import type { SerializableKey } from "src/utils/createSerializableKey";
import type { OneOf, Pretty } from "src/utils/types";
import type { Eval, OneOf } from "src/utils/types";

export type ClientConfig<
TAdapter extends Adapter = Adapter,
TCache extends SimpleCache = SimpleCache,
> = Pretty<ClientOptions<TCache> & ClientAdapterOptions<TAdapter>>;
> = Eval<ClientOptions<TCache> & ClientAdapterOptions<TAdapter>>;

/**
* A client for interacting with a network through an adapter with caching and
Expand Down
4 changes: 2 additions & 2 deletions packages/drift/src/client/contract/Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import {
ReadonlyError,
} from "src/client/BaseClient";
import type { SerializableKey } from "src/utils/createSerializableKey";
import type { AnyObject, EmptyObject, OneOf, Pretty } from "src/utils/types";
import type { AnyObject, EmptyObject, Eval, OneOf } from "src/utils/types";

export type ContractConfig<
TAbi extends Abi = Abi,
TAdapter extends Adapter = Adapter,
TCache extends SimpleCache = SimpleCache,
TClient extends BaseClient<TAdapter, TCache> = BaseClient<TAdapter, TCache>,
> = Pretty<
> = Eval<
ContractParams<TAbi> & ContractClientOptions<TAdapter, TCache, TClient>
>;

Expand Down
8 changes: 3 additions & 5 deletions packages/drift/src/client/contract/MockContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ import type {
import type { SimpleCache } from "src/cache/types";
import type { BaseClient, ClientOptions } from "src/client/BaseClient";
import { MockClient } from "src/client/MockClient";
import {
Contract
} from "src/client/contract/Contract";
import { Contract } from "src/client/contract/Contract";
import { ZERO_ADDRESS } from "src/constants";
import type { FunctionKey, OneOf, OptionalKeys, Pretty } from "src/utils/types";
import type { Eval, FunctionKey, OneOf, OptionalKeys } from "src/utils/types";

export type MockContractConfig<
TAbi extends Abi = Abi,
TAdapter extends MockAdapter = MockAdapter,
TCache extends SimpleCache = SimpleCache,
TClient extends MockClient<TAdapter, TCache> = MockClient<TAdapter, TCache>,
> = Pretty<
> = Eval<
Partial<ContractParams<TAbi>> &
MockContractClientOptions<TAdapter, TCache, TClient>
>;
Expand Down
17 changes: 16 additions & 1 deletion packages/drift/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@ export type MaybeAwaited<T> = T extends Promise<infer U> ? MaybePromise<U> : T;
* Combines members of an intersection into a readable type.
* @see https://x.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg
*/
export type Pretty<T> = { [K in keyof T]: T[K] } & {};
// This is not meant for internal use. It's a public alias for the internal
// `Eval` that uses a name users might be more familiar with.
export type Pretty<T> = Eval<T>;

/**
* Forces TypeScript to evaluate and expand a type instead of displaying it as a
* reference.
*
* @internal
* @privateRemarks
* The `& {}` intersection trick works because it forces TypeScript to create a
* new object type rather than just reference the existing one. It's like
* telling TypeScript "give me a new type that has all these properties" instead
* of "just point to this other type."
*/
export type Eval<T> = { [K in keyof T]: T[K] } & {};

/**
* Replace properties in `T` with properties in `U`.
Expand Down

0 comments on commit acea457

Please sign in to comment.