【发布时间】: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