Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- fix: export the `GenericIdlFuncArgs`, `GenericIdlFuncRets`, and `GenericIdlServiceFields` types from `@dfinity/candid`.

## [3.2.0] - 2025-08-07

- fix: do not subtract the replica permitted clock drift when calculating the ingress expiry.
Expand Down
28 changes: 19 additions & 9 deletions packages/candid/src/idl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1684,8 +1684,15 @@ export class PrincipalClass extends PrimitiveType<PrincipalId> {
}
}

type GenericFuncArgs = [Type, ...Type[]] | [];
type GenericFuncRets = [Type, ...Type[]] | [];
/**
* The generic type of the arguments of an {@link Func|IDL Function}.
*/
export type GenericIdlFuncArgs = [Type, ...Type[]] | [];

/**
* The generic type of the return values of an {@link Func|IDL Function}.
*/
export type GenericIdlFuncRets = [Type, ...Type[]] | [];

/**
* Represents an IDL function reference.
Expand All @@ -1694,8 +1701,8 @@ type GenericFuncRets = [Type, ...Type[]] | [];
* @param annotations Function annotations.
*/
export class FuncClass<
Args extends GenericFuncArgs = GenericFuncArgs,
Rets extends GenericFuncRets = GenericFuncRets,
Args extends GenericIdlFuncArgs = GenericIdlFuncArgs,
Rets extends GenericIdlFuncRets = GenericIdlFuncRets,
> extends ConstructType<[PrincipalId, string]> {
get typeName() {
return IdlTypeName.FuncClass;
Expand Down Expand Up @@ -1806,11 +1813,14 @@ export class FuncClass<
}
}

type GenericServiceFields = Record<string, FuncClass>;
/**
* The generic type of the fields of an {@link Service|IDL Service}.
*/
export type GenericIdlServiceFields = Record<string, FuncClass>;

export class ServiceClass<
K extends string = string,
Fields extends GenericServiceFields = GenericServiceFields,
Fields extends GenericIdlServiceFields = GenericIdlServiceFields,
> extends ConstructType<PrincipalId> {
get typeName() {
return IdlTypeName.ServiceClass;
Expand Down Expand Up @@ -2327,8 +2337,8 @@ export function Rec(): RecClass {
* @returns new FuncClass
*/
export function Func<
Args extends GenericFuncArgs = GenericFuncArgs,
Ret extends GenericFuncRets = GenericFuncRets,
Args extends GenericIdlFuncArgs = GenericIdlFuncArgs,
Ret extends GenericIdlFuncRets = GenericIdlFuncRets,
>(args: Args, ret: Ret, annotations: string[] = []): FuncClass<Args, Ret> {
return new FuncClass(args, ret, annotations);
}
Expand All @@ -2340,7 +2350,7 @@ export function Func<
*/
export function Service<
K extends string = string,
Fields extends GenericServiceFields = GenericServiceFields,
Fields extends GenericIdlServiceFields = GenericIdlServiceFields,
>(t: Fields): ServiceClass<K, Fields> {
return new ServiceClass(t);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/candid/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export * from './candid-ui.ts';
export * from './candid-core.ts';
export * as IDL from './idl.ts';
export {
type GenericIdlFuncArgs,
type GenericIdlFuncRets,
type GenericIdlServiceFields,
} from './idl.ts';
export * from './utils/hash.ts';
export * from './utils/leb128.ts';
export * from './utils/buffer.ts';
Expand Down
Loading