microsoft / microsoft/TypeScript

Feature Request: Display JSDoc Array of Objects as Array

Đang mở
#58,901 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Awaiting More Feedback Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Không có tệp triển khai hoặc bài kiểm thử nào được nêu tên. Tái hiện ví dụ JSDoc trong VSCode và kiểm tra đầu ra hover của TypeScript language-service, sau đó lần theo cách các thuộc tính mảng được tài liệu hóa được biểu diễn và hiển thị. Được xem là hoàn thành khi thuộc tính Object[] được tài liệu hóa xuất hiện dưới dạng một mảng các đối tượng mà vẫn giữ nguyên mô tả của từng thuộc tính, với mức độ bao phủ cho hành vi của ví dụ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, typescript, vscode
Lĩnh vực
developer-experience, tooling
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.