[BUG]: `ModeBar` generated type should be more specific
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- javascript, typescript
- Bereich
- data-visualization
Rechercherichtung
Beginne mit src/types/generated/components/modebar.d.ts, src/components/modebar/attributes.ts und src/types/lib/attributes.d.ts, um nachzuverfolgen, wie ModeBar-Eigenschaften zu TypeScript-Typen werden. Lies src/components/modebar/constants.js, um die Laufzeit-Button-Registry zu verstehen, bevor du die möglichen Ansätze bewertest. Als abgeschlossen gilt die Aufgabe, wenn add und remove den vorgesehenen Button-Namen-Typ offenlegen, uirevision number | string ist und uid vorhanden ist, ohne die generierte Typstruktur zu verlieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 18.3k
- Forks
- 2k
- Ø Merge
- 2 T. 12 Std.
- Gemergte PRs (30 T.)
- 28
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus plotly/plotly.js
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
chore P1 plotly-internal size: 1 task
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
-
chore P3 plotly-internal size: 1 task
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
bug infrastructure P2
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 65/100
Alle Issues in plotly/plotly.js
Ähnliche Issues
-
bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
apache/cloudstack#14222 ·
-
Browser Waiting for: Product Owner
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
getsentry/sentry-javascript#24577 · 1 Kommentar ·
-
curation good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
amponce/archive-movie-browser#186 ·
-
light
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
aemdemos/patients-stryker#253 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
clerk/javascript#9852 ·