microsoft / microsoft/TypeScript

Feature Request: Display JSDoc Array of Objects as Array

Abierto
#58,901 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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!!

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

No se nombra ningún archivo de implementación ni ninguna prueba. Reproduce el ejemplo de JSDoc en VSCode e inspecciona la salida de hover de TypeScript language-service; después, rastrea cómo se representan y muestran las propiedades de array documentadas. Se considera terminado cuando la propiedad Object[] documentada aparece como un array de objetos, conservando las descripciones de las propiedades individuales, con cobertura del comportamiento del ejemplo.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, typescript, vscode
Área
developer-experience, tooling
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.