demergent-labs / azle

A WebAssembly runtime for TypeScript and JavaScript on ICP
MIT License
204 stars 37 forks source link

`Result(Void, T)` is not supported #1387

Open dansteren opened 11 months ago

dansteren commented 11 months ago

Given the following canister:

import { Canister, Ok, Result, text, query, Void } from "azle";

export default Canister({
  method: query([], Result(Void, text), () => {
    return Ok(undefined);
  }),
});

When running dfx deploy, Then I am expecting to have the canister build with the following candid file:

service : () -> {
    method : () -> (variant {Ok; Err: text;});
}

But actually, it currently fails with this error: image

dansteren commented 11 months ago

After discussing as a team, we've decided that Result(Void, X) is not valid. You should instead use Result(Null, X). Looking through the candid reference leaving out a value in a variant is the equivalent of null. The lack of value is not valid. So, we'll continue that pattern.

So, the valid code would be:

import { Canister, Ok, Result, text, query, Void } from "azle";

export default Canister({
  method: query([], Result(Null, text), () => {
    return Ok(null);
  }),
});
dansteren commented 11 months ago

Only thing left is to update the documentation to add this caveat.