【问题标题】:Get default value on storaged u64获取 storaged u64 的默认值
【发布时间】:2021-12-01 00:28:35
【问题描述】:

我想获取存储值,如果不存在,请给我0

const lastDeposit = storage.get<u64>('lastDeposit', u64(0)) || u64(0);

但是编译器抛出

ERROR AS204: Type 'u64' cannot be nullable.

   static get<T>(key: string, defaultValue: T | null = null): T | null {
                                            ~
 in ~lib/near-sdk-core/storage.ts(178,44)

ERROR AS204: Type 'u64' cannot be nullable.

   static get<T>(key: string, defaultValue: T | null = null): T | null {
                                                              ~
 in ~lib/near-sdk-core/storage.ts(178,62)

【问题讨论】:

    标签: nearprotocol


    【解决方案1】:

    您必须以一种永远不允许lastDepositnull 的方式来表达这一点

    这是为我编译的,但有错误

    const lastDeposit: u64 = storage.getSome<u64>('lastDeposit') || 0;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-01
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      • 2012-07-31
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多