VS2019 / Typescript 3.7:如何让 Intellisense 在键入函数时显示函数描述

VS2019 / Typescript 3.7: How to make Intellisense show function description when function is typed

在 module.ts 文件中,我定义了:

/**
 *  My awesome function description
 */
export let myFunc = () => {
    // do something...
    return;
}

在 index.ts 中,我使用这样的函数:

import { myFunc } from "./module.ts";
myFunc();

将鼠标悬停在 "myFunc" 上会给我正确的 Intellisense,包括函数声明中给出的描述 ("My awesome function description"): 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 显示描述?

How can I type the function and have Intellisense show the description?

我觉得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