Skip to content

Commit 34128aa

Browse files
authored
refactor(core): light client provider type definition (#1108)
1 parent e7ef0b0 commit 34128aa

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

.changeset/wide-papayas-think.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@reactive-dot/core": patch
3+
---
4+
5+
Simplified `LightClientProvider` type definition. This change addresses potential issues when `tsconfig.json` has `noEmit` set to `false`.

packages/core/src/providers/light-client/provider.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ type LightClientOptions = {
2727
useExtensionProvider?: boolean;
2828
};
2929

30+
type RelayLightClientProvider<T extends WellknownRelayChainId> =
31+
LightClientProvider & {
32+
addParachain<
33+
TParachainId extends keyof (typeof wellknownChains)[T][1] extends never
34+
? WellknownParachainId
35+
: keyof (typeof wellknownChains)[T][1],
36+
>(
37+
options: AddChainOptions<TParachainId>,
38+
): LightClientProvider;
39+
};
40+
41+
type RootLightClientProvider = {
42+
addRelayChain<TRelayChainId extends WellknownRelayChainId>(
43+
options: AddChainOptions<TRelayChainId>,
44+
): RelayLightClientProvider<TRelayChainId>;
45+
};
46+
3047
export function createLightClientProvider({
3148
useExtensionProvider = true,
3249
}: LightClientOptions = {}) {
@@ -39,9 +56,7 @@ export function createLightClientProvider({
3956
});
4057

4158
return {
42-
addRelayChain<TRelayChainId extends WellknownRelayChainId>(
43-
options: AddChainOptions<TRelayChainId>,
44-
) {
59+
addRelayChain(options) {
4560
const getChainSpec = lazy(() =>
4661
"chainSpec" in options
4762
? Promise.resolve(options.chainSpec)
@@ -64,12 +79,7 @@ export function createLightClientProvider({
6479
return getSmProvider(getRelayChain());
6580
},
6681

67-
addParachain<
68-
TParachainId extends
69-
keyof (typeof wellknownChains)[TRelayChainId][1] extends never
70-
? WellknownParachainId
71-
: keyof (typeof wellknownChains)[TRelayChainId][1],
72-
>(options: AddChainOptions<TParachainId>) {
82+
addParachain(options) {
7383
return addLightClientProvider({
7484
[getProviderSymbol]() {
7585
const chainSpecPromise =
@@ -108,7 +118,7 @@ export function createLightClientProvider({
108118
},
109119
});
110120
},
111-
};
121+
} as RootLightClientProvider;
112122
}
113123

114124
export function isLightClientProvider(

0 commit comments

Comments
 (0)