GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(types): Accept attribute paths in plotly_relayout, relayout, restyle, and update by camdecoster · Pull Request #8126 · plotly/plotly.js Conversation
|
| - name: Type-check TypeScript sources | ||
| run: npm run typecheck | ||
|
|
||
| test-types: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit: could we just add test-types as a second step in the typecheck job above? Is there a reason you want a second runner?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just to make it obvious what the failure is.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /** | ||
| * Consumer-side checks for the `relayout`, `restyle` and `update` types. | ||
| * | ||
| * Nothing here runs. `npm run typecheck` compiles this file against the public entry point. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit:
| * Nothing here runs. `npm run typecheck` compiles this file against the public entry point. | |
| * Nothing here runs. `npm run test-types` compiles this file against the public entry point. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good call. I missed this during a name change.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * autorange keys that flatten nested updates. | ||
| */ | ||
| export interface PlotRelayoutEvent extends Partial<Layout> { | ||
| export interface PlotRelayoutEvent extends LayoutUpdate { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This type contains 6 hand-crafted keys (xaxis.range[0], etc.) but LayoutUpdate doesn't type these keys at all.
This starts to look like 2 sources of truth for these types. And already, the two definitions are drifting:
the hand-crafted keys here define values that are narrower than in LayoutUpdate. xaxis.range[0]?: number misses date axes with values like 2026-10-16.
What do you think about moving the hand-typed keys here into LayoutUpdate with the type widened to include date strings? That way there would be a single definition.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
These actually should have been deleted. LayoutUpdate should handle any of the attribute paths, so we don't need to specify individual ones here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The overloads you add here are good, but can still report "errors" on perfectly valid code.
Example:
import * as Plotly from 'plotly.js'; type RelayoutArg = Parameters<typeof Plotly.relayout>[1]; const wrapped: RelayoutArg = { autosize: true };
There is a red squiggle as typescript evaluates against the "last" overload and completely misses the other valid overload.
Typescript says to put the most generic signature last. What do you think about including a generic "catch-all" overload at the end for these kinds of cases?
export function relayout(root: Root, astr: string | LayoutUpdate, val?: any): Promise<PlotlyHTMLElement>;
The same comment applies to the restyle overloads.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks great! 💃
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[BUG]: Typing issue in relayout()
There was an error while loading. Please reload this page.