带有已通过类型定义的JSDoc在VSCode中进行类型检查

问题描述 投票:0回答:1

我正在用JSDoc和VS Code进行类型检查,我想知道是否有一种方法可以通过设置类型然后将上述类型传递到函数中的方式进行类型检查-我们不必重新delcare这个类型。

例如:

/**
* @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}?`

typescript visual-studio-code vscode-settings jsdoc
1个回答
0
投票

在someFunction2中,result是该函数的局部参数,它遮盖了第一个const结果。这是一个完全不同的变量。因此,VSCode可能认为这是无类型的。

© www.soinside.com 2019 - 2024. All rights reserved.