[BUG]: Typing issue in relayout() #8047
Copy link
Copy link
Open
Labels
Description
Activity
Thanks for the report. This is a limitation of how plotly.js and TS interact. plotly.js allows one to update references as a string like you describe, but TS has no way to know that's valid. IIRC, DefinitelyTyped included some of the more common strings as valid options. I thought I had included some in the new types, but maybe I missed that. I'll take a look and follow up.
I've opened #8050 to resolve this cleanly!
Summary of Fix
- **\ asks/generate_schema_types.mjs\ & \src/types/generated/schema.d.ts**:
- Generates common nested axis/title properties on \Layout\ (\xaxis.autorange, \yaxis.autorange, \xaxis.range, \xaxis.type, \xaxis.title, etc.) for direct IDE autocompletion and hover types.
- Emits template literal index signatures [key: \.\]: any;\ and [key: \[\]: any;\ on \Layout. This allows arbitrary dotted and indexed attribute paths, while strictly preserving excess property checks for non-dotted top-level layout keys (e.g. typos like { titl: '...' }\ continue to be caught and rejected by TypeScript).
- **\src/types/core/api.d.ts**:
- Added 2-parameter string attribute path overloads for \Plotly.relayout(root, astr, val)\ and \Plotly.restyle(root, astr, val, traces?).
- Updated
estyle\ and \update\ to allow \Partial | Record<string, any>\ for dotted trace attribute updates.
- **\lib/index.d.ts\ & \src/types/core/layout.d.ts**:
- Exported \LayoutUpdate\ alias (\Partial).
Verified via
pm run typecheck,
pm run schema-typegen-diff-check, and
pm run lint\ (all clean).- **\ asks/generate_schema_types.mjs\ & \src/types/generated/schema.d.ts**:
I'll take a look at the PR. I have opinions about how this should be added.
Description
Updating to plotly 4.1 caused a typing issue with
relayout()For this line of code:
I get the following error from typescript:

I checked the code here at:
https://github.com/plotly/plotly.js/blob/v4.1.1/src/types/core/api.d.ts#L212
export function relayout(root: Root, layout: Partial<Layout>)Here the
Partial<Layout>seems to cause the issue.Notes
Versions:
Alternatives
I tried:
but this will replace the existing xaxis properties like anchor, color, etc. will be removed -- i just want to update the
autorangein this line of code