microsoft / microsoft/TypeScript

Feature Request: Display JSDoc Array of Objects as Array

オープン
#58,901 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Hey guys,

I tried searching for a similar issue, but couldn't find one. If there is another, I'm happy to close this one. Essentially, when specifying that a particular entity is an array of objects with a definite shape, I would like it if those were displayed as an actual array. Given the following Javascript:

/**
 * @param {Object} params
 * @param {Object[]} params.items - Array of items
 * @param {string} params.items[].name - Name of the item
 * @param {string} params.items[].value - Value of the item
*/
function myFunc({ items = []}){
    items.map(item => {
        console.log(item.name, item.value)
    })
}

Currently, on hover, VSCode displays the type hinting as:

function myFunc({ items }: {
    items: {
        name: string;
        value: string;
    };
}): void

However, this makes it appear that items is an object. That is incorrect because items is instead an array of objects, and is specified as such in the JSDoc. I would expect something akin to when you specify the properties inline:

JS:
/**
 * @param {Object} params
 * @param {{name: string, data: string}[]} params.items - Array of items
*/
function myFunc({ items = []}){
    items.map(item => {
        console.log(item.name, item.value)
    })
}
Hover:
function myFunc({ items }: {
    items: {
        name: string;
        data: string;
    }[];
}): void

The problem with using the inline format is the lack of an explanation of individual properties, and some object shapes can get very long, and even be nested. Additionally, the above solution waits until the end of the object definition to denote that the property should be an array. It seems that it would be more user-friendly if it was denoted as an array at the beginning, like this:

function myFunc({ items }: {
    items: [{
        name: string;
        data: string;
    }];
}): void

Thanks for your time and the great product!!

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

実装ファイルもテストも指定されていません。VSCode で JSDoc の例を再現し、TypeScript language-service の hover 出力を調べたうえで、ドキュメント化された配列プロパティがどのように表現され、表示されるかを追跡します。完了条件は、ドキュメント化された Object[] プロパティがオブジェクトの配列として表示され、個々のプロパティの説明が保持されること、および例の動作をカバーすることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, typescript, vscode
領域
developer-experience, tooling
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。