Skip to content

Commit e64d4a3

Browse files
committed
perf: prefer interface over type alias
1 parent b31f3f7 commit e64d4a3

44 files changed

Lines changed: 175 additions & 172 deletions

Some content is hidden

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

.changeset/young-ends-grow.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@reactive-dot/wallet-polkadot-vault": patch
3+
"@reactive-dot/wallet-readonly": patch
4+
"@reactive-dot/wallet-ledger": patch
5+
"@reactive-dot/wallet-mimir": patch
6+
"@reactive-dot/react": patch
7+
"@reactive-dot/core": patch
8+
"@reactive-dot/vue": patch
9+
---
10+
11+
Prefer `interface` over `type` alias for object types and use `extends` instead of intersection types (`&`), yielding better TypeScript type-checking performance and more consistent error messages.

examples/react/src/account-select.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { WalletAccount } from "@reactive-dot/core/wallets.js";
22
import { useConnectedWallets, useAccounts } from "@reactive-dot/react";
33
import { type ReactNode, useState } from "react";
44

5-
type AccountSelectProps = {
5+
interface AccountSelectProps {
66
children: (account: WalletAccount) => ReactNode;
7-
};
7+
}
88

99
export function AccountSelect({ children }: AccountSelectProps) {
1010
const connectedWallets = useConnectedWallets();

examples/react/src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function App() {
5050
);
5151
}
5252

53-
type ExampleProps = { chainName: string };
53+
interface ExampleProps { chainName: string }
5454

5555
function Example({ chainName }: ExampleProps) {
5656
const resetQueryError = useQueryErrorResetter();

examples/react/src/ink-contract.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export function InkContracts() {
1717
);
1818
}
1919

20-
type ContractProps = {
20+
interface ContractProps {
2121
address: string;
22-
};
22+
}
2323

2424
function Psp22TokenInfo({ address }: ContractProps) {
2525
const [timestamp, [tokenName, tokenDecimals, tokenSymbol, totalSupply]] =

examples/react/src/query.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ function SpendableBalances() {
138138
);
139139
}
140140

141-
type SpendableBalanceProps = {
141+
interface SpendableBalanceProps {
142142
account: PolkadotAccount;
143-
};
143+
}
144144

145145
function SpendableBalance({ account }: SpendableBalanceProps) {
146146
return (
@@ -199,10 +199,10 @@ function PendingPoolRewards() {
199199
);
200200
}
201201

202-
type PendingRewardsProps = {
202+
interface PendingRewardsProps {
203203
account: PolkadotAccount;
204204
rewards: bigint;
205-
};
205+
}
206206

207207
function PendingRewards({ account, rewards }: PendingRewardsProps) {
208208
return (

examples/react/src/wallet-connection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export function WalletConnection() {
2727
);
2828
}
2929

30-
type WalletItemProps = {
30+
interface WalletItemProps {
3131
wallet: Wallet;
32-
};
32+
}
3333

3434
function WalletItem({ wallet }: WalletItemProps) {
3535
const connectedWallets = useConnectedWallets();

packages/core/src/actions/get-block-extrinsics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ type Extra = Partial<{
4949
[key: string]: unknown;
5050
}>;
5151

52-
type Call = {
52+
interface Call {
5353
module: string;
5454
func: string;
5555
args: unknown;
56-
};
56+
}
5757

5858
type Extrinsic = { version: number; call: Call } & (
5959
| { signed: false }

packages/core/src/actions/get-block.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { PolkadotClient } from "polkadot-api";
33
import { of } from "rxjs";
44
import { expect, it } from "vitest";
55

6-
type DummyBlock = { id: string };
6+
interface DummyBlock { id: string }
77

88
it("should return the best block when options.tag is 'best'", () =>
99
new Promise<void>((resolve) => {

packages/core/src/actions/get-block.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { PolkadotClient } from "polkadot-api";
22
import { map } from "rxjs";
33

4-
export type GetBlockOptions = {
4+
export interface GetBlockOptions {
55
tag?: "best" | "finalized";
6-
};
6+
}
77

88
export function getBlock<TOptions extends GetBlockOptions>(
99
client: PolkadotClient,

packages/core/src/config.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@ import type { Wallet, WalletProvider } from "./wallets/index.js";
55
import type { JsonRpcProvider } from "polkadot-api";
66
import type { ChainDefinition } from "polkadot-api";
77

8-
export type ChainConfig = {
8+
export interface ChainConfig {
99
readonly descriptor: ChainDefinition | UnsafeDescriptor;
1010
readonly provider: Gettable<JsonRpcProvider | LightClientProvider>;
11-
};
11+
}
1212

13-
export type Config<
14-
TChains extends Readonly<Record<string, ChainConfig>> = Readonly<
15-
Record<string, ChainConfig>
16-
>,
17-
TTargetChainIds extends Extract<keyof TChains, string>[] = Extract<
18-
keyof TChains,
19-
string
20-
>[],
21-
> = {
13+
export interface Config<
14+
TChains extends Readonly<Record<string, ChainConfig>> = Readonly<Record<string, ChainConfig>>,
15+
TTargetChainIds extends Extract<keyof TChains, string>[] = Extract<keyof TChains, string>[],
16+
> {
2217
readonly chains: TChains;
2318
readonly targetChains?: TTargetChainIds;
2419
readonly wallets?: Array<WalletProvider | Wallet>;
@@ -36,7 +31,7 @@ export type Config<
3631
* @defaultValue false
3732
*/
3833
readonly ssr?: boolean;
39-
};
34+
}
4035

4136
export function defineConfig<
4237
const TChains extends Readonly<Record<string, ChainConfig>>,

0 commit comments

Comments
 (0)