【问题标题】:Type Checking in VSCode with JSDoc With Passed Type Defs在 VSCode 中使用带有传递的类型定义的 JSDoc 进行类型检查
【发布时间】:2020-04-17 16:54:33
【问题描述】:

我正在尝试使用 JSDoc 和 VS Code 进行类型检查,我想知道是否可以通过设置类型然后将上述类型传递给函数的方式进行类型检查- 我们不必重新定义类型。

例如:

/**
* @type {string}
*/
const result = someFunction1(args);

someFunction2(result)

//here - when I type result * 5... VS code announces an error... great! work as expected


const someFunction2 = (result)=>{
//here - when I type result * 5... VS code does NOT announce an error... :( I was hoping it would...
}

有没有办法让 VSCode 宣布错误而无需重新声明 @type {string}? `

【问题讨论】:

  • someFunction2 中,result 是该函数的一个局部参数,它会影响第一个const result。这是一个完全不同的变量。所以 VSCode 可能认为那是无类型的。

标签: typescript visual-studio-code vscode-settings jsdoc


【解决方案1】:

在 someFunction2 中,result 是该函数的一个局部参数,它隐藏第一个 const 结果。这是一个完全不同的变量。所以 VSCode 可能认为那是无类型的。

我首先将其作为评论发布,因为我不确定这是否是你的全部问题,但也许是:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 2014-04-08
    • 2023-03-15
    • 2020-03-12
    相关资源
    最近更新 更多