当我在很多地方使用函数签名时,我经常将它们保存为单独的类型。
问题是,每当我在接口或复合类型中使用这样的类型时,当鼠标悬停在属性上时,它不会自动向我显示底层类型的文档。。。
/**
* Documentation for function that is used in multiple places
*/
export type MyFunction = () => void
export interface SomeInferface {
/**
* I HAVE to duplicate the documentation manually here, if not, it won't show up in the interface...
*/
myFunction: MyFunction
}
export type SomeType = {
/**
* I HAVE to duplicate the documentation manually here, if not, it won't show up in the type...
*/
myFunction: MyFunction
}
这使得它对使用我的库的开发人员来说非常不友好。因此,为了减轻这种情况,我必须手动复制每个接口和使用它的复合类型中的类型的文档块
但如果我更改了它,却忘记在某个地方更新它,这反过来又很容易出错。。。
如何自动让VSCode在接口和复合类型中显示类型文档?
这是一个功能请求,当您将鼠标悬停在值上时,它会跟踪包括值类型的文档
然而,VS Code今天所做的是意料之中的,因为您正在记录两件不同的事情。示例中:
/**
* Documentation for function that is used in multiple places
*/
export type MyFunction = () => void
该文档适用于MyFunction
类型。
但是:
export interface SomeInferface {
/**
* I HAVE to duplicate the documentation manually here, if not, it won't show up in the interface...
*/
myFunction: MyFunction
}
该文档用于属性CCD_ 2。
通常,您应该为属性本身提供不同于属性类型的文档
在各处搜索了很长时间后,这似乎还不可能。这是一个开放功能请求:https://github.com/microsoft/TypeScript/issues/37876