【问题标题】:Is `!any` valid in JSDoc as the type of a parameter?`!any` 在 JSDoc 中作为参数类型有效吗?
【发布时间】:2023-02-08 07:23:25
【问题描述】:

!any 在 JSDoc 中作为参数类型有效吗?这意味着什么?

我试图用它来将变量限制为除“null”或“undefined”之外的任何类型。但至少在 VSCode 中,似乎没有强制执行此检查。

【问题讨论】:

    标签: jsdoc


    【解决方案1】:

    您可以使用NonNullable实用程序类型

    /**@type {string | null | undefined}*/
    let foo;
    
    /**@type {NonNullable<typeof foo>}*/(foo).toLowerCase();
    

    https://github.com/microsoft/TypeScript/issues/23405

    【讨论】:

      猜你喜欢
      • 2012-12-17
      • 2018-09-05
      • 1970-01-01
      • 2013-04-07
      • 2021-12-03
      • 2021-04-19
      • 2020-03-11
      • 2023-03-15
      • 2019-03-15
      相关资源
      最近更新 更多