microsoft / microsoft/TypeScript
Feature Request: Display JSDoc Array of Objects as Array
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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!!
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Keine Implementierungsdatei oder kein Test wird genannt. Reproduziere das JSDoc-Beispiel in VSCode und untersuche die Hover-Ausgabe des TypeScript language-service; verfolge anschließend, wie dokumentierte Array-Eigenschaften dargestellt und angezeigt werden. Als abgeschlossen gilt, dass die dokumentierte Object[]-Eigenschaft als Array von Objekten erscheint und dabei die Beschreibungen der einzelnen Eigenschaften erhalten bleiben, mit einer Abdeckung des Beispielverhaltens.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript, vscode
- Bereich
- developer-experience, tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100