Skip to content

Commit fda1ae3

Browse files
authored
fix: export generic types from IDL module (#1099)
* fix: export generic types from IDL module * docs: add jsdocs and update changelog
1 parent 3f7f4d6 commit fda1ae3

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
- fix: export the `GenericIdlFuncArgs`, `GenericIdlFuncRets`, and `GenericIdlServiceFields` types from `@dfinity/candid`.
6+
57
## [3.2.0] - 2025-08-07
68

79
- fix: do not subtract the replica permitted clock drift when calculating the ingress expiry.

packages/candid/src/idl.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,15 @@ export class PrincipalClass extends PrimitiveType<PrincipalId> {
16841684
}
16851685
}
16861686

1687-
type GenericFuncArgs = [Type, ...Type[]] | [];
1688-
type GenericFuncRets = [Type, ...Type[]] | [];
1687+
/**
1688+
* The generic type of the arguments of an {@link Func|IDL Function}.
1689+
*/
1690+
export type GenericIdlFuncArgs = [Type, ...Type[]] | [];
1691+
1692+
/**
1693+
* The generic type of the return values of an {@link Func|IDL Function}.
1694+
*/
1695+
export type GenericIdlFuncRets = [Type, ...Type[]] | [];
16891696

16901697
/**
16911698
* Represents an IDL function reference.
@@ -1694,8 +1701,8 @@ type GenericFuncRets = [Type, ...Type[]] | [];
16941701
* @param annotations Function annotations.
16951702
*/
16961703
export class FuncClass<
1697-
Args extends GenericFuncArgs = GenericFuncArgs,
1698-
Rets extends GenericFuncRets = GenericFuncRets,
1704+
Args extends GenericIdlFuncArgs = GenericIdlFuncArgs,
1705+
Rets extends GenericIdlFuncRets = GenericIdlFuncRets,
16991706
> extends ConstructType<[PrincipalId, string]> {
17001707
get typeName() {
17011708
return IdlTypeName.FuncClass;
@@ -1806,11 +1813,14 @@ export class FuncClass<
18061813
}
18071814
}
18081815

1809-
type GenericServiceFields = Record<string, FuncClass>;
1816+
/**
1817+
* The generic type of the fields of an {@link Service|IDL Service}.
1818+
*/
1819+
export type GenericIdlServiceFields = Record<string, FuncClass>;
18101820

18111821
export class ServiceClass<
18121822
K extends string = string,
1813-
Fields extends GenericServiceFields = GenericServiceFields,
1823+
Fields extends GenericIdlServiceFields = GenericIdlServiceFields,
18141824
> extends ConstructType<PrincipalId> {
18151825
get typeName() {
18161826
return IdlTypeName.ServiceClass;
@@ -2327,8 +2337,8 @@ export function Rec(): RecClass {
23272337
* @returns new FuncClass
23282338
*/
23292339
export function Func<
2330-
Args extends GenericFuncArgs = GenericFuncArgs,
2331-
Ret extends GenericFuncRets = GenericFuncRets,
2340+
Args extends GenericIdlFuncArgs = GenericIdlFuncArgs,
2341+
Ret extends GenericIdlFuncRets = GenericIdlFuncRets,
23322342
>(args: Args, ret: Ret, annotations: string[] = []): FuncClass<Args, Ret> {
23332343
return new FuncClass(args, ret, annotations);
23342344
}
@@ -2340,7 +2350,7 @@ export function Func<
23402350
*/
23412351
export function Service<
23422352
K extends string = string,
2343-
Fields extends GenericServiceFields = GenericServiceFields,
2353+
Fields extends GenericIdlServiceFields = GenericIdlServiceFields,
23442354
>(t: Fields): ServiceClass<K, Fields> {
23452355
return new ServiceClass(t);
23462356
}

packages/candid/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export * from './candid-ui.ts';
22
export * from './candid-core.ts';
33
export * as IDL from './idl.ts';
4+
export {
5+
type GenericIdlFuncArgs,
6+
type GenericIdlFuncRets,
7+
type GenericIdlServiceFields,
8+
} from './idl.ts';
49
export * from './utils/hash.ts';
510
export * from './utils/leb128.ts';
611
export * from './utils/buffer.ts';

0 commit comments

Comments
 (0)