Skip to content

Commit

Permalink
fix manual and void
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Sep 29, 2023
1 parent dbb334d commit 54629d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/lib_functional/candid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
AzleResult,
Result,
AzleTuple,
AzleText
AzleText,
AzleVoid
} from '../../lib_new';

export type TypeMapping<T> = T extends () => any
Expand Down Expand Up @@ -73,7 +74,7 @@ export type TypeMapping<T> = T extends () => any
? float64
: T extends AzleFloat32
? float32
: T extends never[]
: T extends AzleVoid
? void
: T extends AzleTuple<infer U>
? { [K in keyof U]: TypeMapping<U[K]> }
Expand Down
4 changes: 2 additions & 2 deletions src/lib_new/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class Principal extends DfinityPrincipal {
* a value, or `None` and does not.
*/
export type Opt<Value> = [Value] | [];
export const Void: [] = [];
export const Void: AzleVoid = AzleVoid as any;
export type Void = void;

/**
Expand Down Expand Up @@ -302,6 +302,6 @@ export function Tuple<T extends any[]>(...types: T): AzleTuple<T> {
return new AzleTuple(types);
}

export function Manual(t: any): void {
export function Manual(t: any): AzleVoid {
return t;
}
14 changes: 6 additions & 8 deletions src/lib_new/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,13 @@ export function toParamIDLTypes(idl: CandidClass[]): IDL.Type<any>[] {
}

export function toReturnIDLType(returnIdl: ReturnCandidClass): IDL.Type<any>[] {
if (Array.isArray(returnIdl)) {
// If Void
if (returnIdl.length === 0) {
return [];
}
// Should be unreachable
return [];
const idlType = toIDLType(returnIdl, []);

if (Array.isArray(idlType)) {
return [...idlType];
}
return [toIDLType(returnIdl, [])];

return [idlType];
}

type CandidMap = { [key: string]: any };
Expand Down

0 comments on commit 54629d0

Please sign in to comment.