[BUG]: `ModeBar` generated type should be more specific
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript, typescript
- Lĩnh vực
- data-visualization
Hướng nghiên cứu
Bắt đầu với src/types/generated/components/modebar.d.ts, src/components/modebar/attributes.ts và src/types/lib/attributes.d.ts để theo dõi cách các thuộc tính của ModeBar trở thành các kiểu TypeScript. Đọc src/components/modebar/constants.js để hiểu registry nút trong runtime trước khi đánh giá các cách tiếp cận khả thi. Được xem là hoàn thành khi add và remove expose kiểu tên nút dự kiến, uirevision là number | string và uid hiện diện mà không làm mất cấu trúc kiểu được generated.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
The generated ModeBar type in src/types/generated/components/modebar.d.ts is less specific than the hand-written ModeBar in @types/plotly.js. The type generator faithfully maps valType: 'string' to string and valType: 'any' to any, but this loses semantic type information for the add, remove, and uirevision properties.
| Property | Generated type | Expected type (per DT) |
|---|---|---|
add |
string | string[] |
ModeBarDefaultButtons | ModeBarDefaultButtons[] |
remove |
string | string[] |
ModeBarDefaultButtons | ModeBarDefaultButtons[] |
uirevision |
any |
number | string |
uid |
missing | string |
Consumers lose autocomplete for valid modebar button names when using layout.modebar.add or layout.modebar.remove.
Steps to reproduce
- Use
layout.modebar.addin a TypeScript project importing from plotly.js - Observe that the type accepts any
stringinstead of suggesting valid button names like'lasso2d','select2d','zoom2d', etc.
Notes
Root cause: The add and remove attributes in src/components/modebar/attributes.ts use valType: 'string' with arrayOk: true. The type generation pipeline (ValTypeToTS in src/types/lib/attributes.d.ts) already supports narrowing StringAttr to a literal union when a values array is provided — but the modebar attributes don't provide one. The button names are dynamically computed at runtime in src/components/modebar/constants.js (foreButtons is built by iterating over the button registry), so they can't be passed as a static as const array.
Possible solutions:
-
Override the generated type in
layout.d.ts— Import the generatedModeBarand re-export a refined version usingOmit+ tighter property types. Keeps the generated base while tightening the public API. Low effort, no changes to the generator or attribute system. -
Inline static
valuesin the attribute definition — Addvalues: ['lasso2d', 'select2d', ...] as constdirectly to theaddandremoveattributes insrc/components/modebar/attributes.ts. The existingValTypeToTSconditional would then produce the union automatically. Downside: duplicates the button list (source of truth is the button registry, not this array). -
Make
foreButtonsstatically typed — Convertsrc/components/modebar/constants.jsto TypeScript with staticas constarrays instead of dynamically computing the list from the button registry. The attributes could then reference the const array asvalues. Downside: requires restructuring how buttons are registered and breaks the dynamic discovery pattern.
- Ngôn ngữ chính
- JavaScript
- Star
- 18.3k
- Fork
- 2k
- Merge trung bình
- 2 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 28
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của plotly/plotly.js
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
chore P1 plotly-internal size: 1 task
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
-
chore P3 plotly-internal size: 1 task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
bug infrastructure P2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
Tất cả issue của plotly/plotly.js
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
avniproject/avni-client#2135 ·
-
automated broken-link
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
agent/security hive/hosted-available-lke648397-260827-5n31 security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
babalae/bettergi-scripts-list#3674 ·
-
A-Release-Notes C-Editing D-Modest S-Ready-For-Implementation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bevyengine/bevy-website#2595 ·