V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
KouShuiYu
V2EX  ›  TypeScript

不太熟悉 TypeScript, 这种问题怎么优雅的解决? 提示:不能调用可能是“未定义”的对象。ts(2722)

  •  
  •   KouShuiYu · 2021-09-23 16:52:35 +08:00 · 829 次点击
    这是一个创建于 936 天前的主题,其中的信息可能已经有所发展或是发生改变。
    const checkCustom = (rule:rule, value: unknown) => {
      const { custom } = rule;
      if (toRawType(custom) !== 'Function') {
        throw new Error('custom need function type values');
      }
      return custom(rule, value);
    };
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1440 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 23:56 · PVG 07:56 · LAX 16:56 · JFK 19:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.