在module.ts文件中,我定义了:
/**
* My awesome function description
*/
export let myFunc = () => {
// do something...
return;
}
以及在index.ts中,我使用如下功能:
import { myFunc } from "./module.ts";
myFunc();
将鼠标悬停在“ myFunc”上会给我适当的Intellisense,包括函数声明中给出的描述(“我的真棒函数描述”):link to screenshot: Intellisense showing function description
但是,如果我在模块中声明类型并将其应用于函数声明,例如:
declare global {
/** MyFunc Type Def */
type myFuncType = () => void;
}
/**
* My awesome function description
*/
export let myFunc:myFuncType = () => {
// do something...
return;
}
然后,现在Intellisense在index.ts中不再显示功能描述:link to screenshot: Intellisense not showing function description
在定义文件module.ts中,Intellisense在两种情况下均起作用。
如何键入功能并让Intellisense显示说明?
我如何键入该功能并让Intellisense显示说明?
我认为module.ts文件中编写的函数有问题。您未指定功能,缺少()
。因此,当您将其称为myFunc()时,找不到特定的函数,因此缺少描述文件。
并且您只需要在定义它时添加()
。您可以参考已经成功测试的示例。
declare global {
/** MyFunc Type Def */
type myFuncType = () => void;
}
/**
* My awesome function description
*/
export let myFunc=(): myFuncType =>{
// do something...
return;
}
希望它可以帮助您。
TypeScript刚刚将报告的问题确认为错误,请参见
github.com/microsoft/TypeScript/issues/35570#issue-534531954