fix(types): support nested attribute path strings in relayout, restyle, and update - #8050
Open
CAOShurong wants to merge 2 commits into
Open
CAOShurong wants to merge 2 commits into
CAOShurong wants to merge 2 commits into
Conversation
…e, and update In plotly.js runtime, Plotly.relayout, Plotly.restyle, and Plotly.update support updating nested properties using dotted attribute paths (e.g. 'xaxis.autorange', 'xaxis.range[0]', 'annotations[0].text') as well as the 2-parameter string invocation form (Plotly.relayout(gd, 'xaxis.autorange', true)). - Update tasks/generate_schema_types.mjs to generate common nested axis and title properties alongside dotted/indexed template literal index signatures on Layout, while preserving strict excess-property checking on top-level layout typos. - Add 2-parameter string attribute path overloads for relayout and restyle in api.d.ts. - Allow Partial<Data> | Record<string, any> in restyle and update trace arguments. - Export LayoutUpdate type alias in layout.d.ts and lib/index.d.ts. - Regenerate src/types/generated/schema.d.ts. Fixes plotly#8047
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
In plotly.js runtime,
Plotly.relayout,Plotly.restyle, andPlotly.updatesupport updating nested properties using dot/bracket attribute paths (such as'xaxis.autorange','xaxis.range[0]','annotations[0].text'), as well as the 2-parameter string invocation formPlotly.relayout(gd, 'xaxis.autorange', true).With the v4.1 TypeScript definitions, calling
relayout()with nested attribute path keys resulted in a type error ('xaxis.autorange' does not exist in type 'Partial<Layout>') becauseLayoutlacked nested attribute path signatures, and only the 2-argument object overload was declared.Changes
tasks/generate_schema_types.mjs&src/types/generated/schema.d.ts:Layout(xaxis.autorange,yaxis.autorange,xaxis.range,xaxis.type,xaxis.title, etc.) for IDE autocompletion and hover documentation.[key:${string}.${string}]: any;and[key:${string}[${string}]: any;toLayout, allowing any arbitrary dotted or indexed attribute paths while strictly preserving excess-property checks for typos on top-level layout keys (e.g.titl: 'abc'is still caught and rejected as a typo).src/types/core/api.d.ts:relayout(root, astr, val).restyle(root, astr, val, traces?).Partial<Data> | Record<string, any>inrestyleandupdateto support dotted attribute updates on traces.src/types/core/layout.d.ts&lib/index.d.ts:LayoutUpdate = Partial<Layout>type alias.Verification
npm run typecheck(tsc --noEmit) passes with 0 errors.npm run schema-typegen-diff-checkpasses with 0 errors (clean sync with generator).npm run lintpasses with 0 errors.{ titl: 'New Title' }) continue to be caught and rejected by TypeScript with errorTS2561 / TS2353.Fixes #8047.