From fb13aba4ce9819a663edebb677c0fb7440b68ac4 Mon Sep 17 00:00:00 2001 From: ilbertt Date: Mon, 11 Aug 2025 20:41:07 +0200 Subject: [PATCH 1/2] fix: export generic types from IDL module --- packages/candid/src/idl.ts | 18 +++++++++--------- packages/candid/src/index.ts | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/candid/src/idl.ts b/packages/candid/src/idl.ts index 6a6205259..591359786 100644 --- a/packages/candid/src/idl.ts +++ b/packages/candid/src/idl.ts @@ -1684,8 +1684,8 @@ export class PrincipalClass extends PrimitiveType { } } -type GenericFuncArgs = [Type, ...Type[]] | []; -type GenericFuncRets = [Type, ...Type[]] | []; +export type GenericIdlFuncArgs = [Type, ...Type[]] | []; +export type GenericIdlFuncRets = [Type, ...Type[]] | []; /** * Represents an IDL function reference. @@ -1694,8 +1694,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; @@ -1806,11 +1806,11 @@ export class FuncClass< } } -type GenericServiceFields = Record; +export type GenericIdlServiceFields = Record; export class ServiceClass< K extends string = string, - Fields extends GenericServiceFields = GenericServiceFields, + Fields extends GenericIdlServiceFields = GenericIdlServiceFields, > extends ConstructType { get typeName() { return IdlTypeName.ServiceClass; @@ -2327,8 +2327,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 { return new FuncClass(args, ret, annotations); } @@ -2340,7 +2340,7 @@ export function Func< */ export function Service< K extends string = string, - Fields extends GenericServiceFields = GenericServiceFields, + Fields extends GenericIdlServiceFields = GenericIdlServiceFields, >(t: Fields): ServiceClass { return new ServiceClass(t); } diff --git a/packages/candid/src/index.ts b/packages/candid/src/index.ts index 34cae43d0..b7cfc5e12 100644 --- a/packages/candid/src/index.ts +++ b/packages/candid/src/index.ts @@ -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'; From b6adbc1b6bd5a39cd05af3425d989aabad611e1b Mon Sep 17 00:00:00 2001 From: ilbertt Date: Mon, 11 Aug 2025 20:51:35 +0200 Subject: [PATCH 2/2] docs: add jsdocs and update changelog --- CHANGELOG.md | 2 ++ packages/candid/src/idl.ts | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 552de58a8..6decd667e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/packages/candid/src/idl.ts b/packages/candid/src/idl.ts index 591359786..9873efb1c 100644 --- a/packages/candid/src/idl.ts +++ b/packages/candid/src/idl.ts @@ -1684,7 +1684,14 @@ export class PrincipalClass extends PrimitiveType { } } +/** + * 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[]] | []; /** @@ -1806,6 +1813,9 @@ export class FuncClass< } } +/** + * The generic type of the fields of an {@link Service|IDL Service}. + */ export type GenericIdlServiceFields = Record; export class ServiceClass<