为什么 VS Code 中 TypeScript 对象属性的建议描述和悬停信息不显示属性类型的文档注释?

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

最容易在下图中看到该问题,因为该问题与 VSCode 中显示类型信息和注释的弹出框有关。

这是代码,但是,TS Playground 甚至不显示在 VSCode 中起作用的注释,所以我会避免使用它。

模板文字类型的注释也会出现此问题。

/**
 * Special documented string to reuse this comment.
 */
type SpecialString = string;

interface Options {
  /** Foo */
  x: number;
  /** Bar */
  y: number;
  s: SpecialString;
}

const fn1 = (options: Options) => {
  console.log('foo');
};

/*
Desired behavior is how the comments appear in the popup when passing in
prop `x` and `x` but the comment is missing when passing in `s`.
*/
// fn1({})

// I don't want have to paste the same comment onto @param for both fn2 and 3
const fn2 = (special: SpecialString) => console.log(special);
const fn3 = (special: SpecialString, x: number) => console.log('foo');

/*
The 'Special' comment is missing when passing in the arg unless the comment
is pasted into an @param on both fn2 and fn3.
*/
// fn2();

interface SpecialStrings {
  /** Special comment */
  special: string;
}

const fn4 = (special: SpecialStrings['special']) => console.log(special);
/*
This also doesn't work to show the comment when passing in the arg.
*/
// fn4();
typescript visual-studio-code jsdoc
1个回答
0
投票

这不是一个非常令人满意的答案,但我很确定它就是这样。如果该类型的属性本身没有文档注释,那么如果 TypeScript 能够显示该类型的文档注释,那可能会很好。您可以将其作为功能请求提出。以前可能已经有人要求过这个问题,但我在搜索查询中找不到现有的问题票证。

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