The CandidType object Opt corresponds to the Candid type opt, is inferred to be a TypeScript Opt<T>, and will be decoded into a JavaScript Object at runtime.

It is a variant with Some and None cases. At runtime if the value of the variant is Some, the Some property of the variant object will have a value of the enclosed Opt type at runtime.

TypeScript or JavaScript:

import { bool, Canister, None, Opt, query, Some } from 'azle';

export default Canister({
    getOptSome: query([], Opt(bool), () => {
        return Some(true); // equivalent to { Some: true }
    getOptNone: query([], Opt(bool), () => {
        return None; //equivalent to { None: null}


service : () -> {
    getOptNone : () -> (opt bool) query;
    getOptSome : () -> (opt bool) query;


dfx canister call candid_canister getOptSome
(opt true)

dfx canister call candid_canister getOptNone