Repository navigation
[bpk-component-barchart] Migrate to TypeScript - #4755
Conversation
Migrates bpk-component-barchart from JavaScript to TypeScript as described in #4742. - Replaced prop-types with TypeScript interfaces - Converted defaultProps to ES6 destructure defaults - Renamed .js source/test/story files to .tsx/.ts - Removed Flow type annotations - Preserved Apache 2.0 license headers Closes #4742
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Migrates bpk-component-barchart toward TypeScript by introducing shared TS types and replacing Flow/PropTypes patterns with TypeScript typing.
Changes:
- Added a shared
common-types.tsand updated components/utils to consume these types. - Removed Flow annotations and most PropTypes usage; moved toward destructured default values.
- Renamed some components to
.tsx(e.g.,BpkChartMargin,BpkBarchartBars) and updated tests/stories accordingly.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/backpack-web/src/bpk-component-barchart/src/utils.js | Introduces TS type usage and refines helper typings. |
| packages/backpack-web/src/bpk-component-barchart/src/utils-test.js | Adds TS annotations / TS suppressions in tests. |
| packages/backpack-web/src/bpk-component-barchart/src/themeAttributes.js | Adds typed theme attribute list export. |
| packages/backpack-web/src/bpk-component-barchart/src/themeAttributes-test.js | Removes Flow header. |
| packages/backpack-web/src/bpk-component-barchart/src/orientation.js | Adds TS Orientation typing to constants. |
| packages/backpack-web/src/bpk-component-barchart/src/customPropTypes.js | Refactors custom validator with TS types. |
| packages/backpack-web/src/bpk-component-barchart/src/customPropTypes-test.js | Removes Flow header. |
| packages/backpack-web/src/bpk-component-barchart/src/common-types.ts | Adds shared TS types for chart components/scales/events. |
| packages/backpack-web/src/bpk-component-barchart/src/accessibility-test.js | Removes Flow header. |
| packages/backpack-web/src/bpk-component-barchart/src/RTLtransforms.js | Adds TS typing for margin + generics for array transform. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkChartMargin.tsx | Converts BpkChartMargin component to TSX and uses Margin type. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkChartMargin.js | Deletes old Flow + PropTypes implementation. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkChartMargin-test.js | Updates spacing setup to pixel values via remToPx. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkChartGridLines.js | Refactors gridlines component typing and tick calculation. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkChartGridLines-test.js | Adds TS suppression for d3-scale import. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkChartDataTable.js | Removes PropTypes and uses BarPoint typing for table content. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkChartDataTable-test.js | Removes Flow header. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkChartAxis.js | Refactors axis config/props typing and tick calculation. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkChartAxis-test.js | Adds TS suppression for d3-scale import. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchartDefs.js | Removes Flow header. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchartDefs-test.js | Removes Flow header. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchartBars.tsx | Converts bars renderer to TSX with shared types. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchartBars.js | Deletes old Flow + PropTypes implementation. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchartBars-test.js | Adds TS suppression for d3-scale import. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchartBar.js | Removes PropTypes and adds TS-esque event typings/casts. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchartBar-test.js | Removes Flow header. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchart.stories.js | Adds TS types/casts for stories and replaces nulls with undefineds. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchart.js | Refactors main component props/defaults toward TS types and removes PropTypes. |
| packages/backpack-web/src/bpk-component-barchart/src/BpkBarchart-test.js | Removes Flow header. |
| packages/backpack-web/src/bpk-component-barchart/index.js | Removes Flow header. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
The identity branch in getAxisConfig was returning the raw identity function instead of applying the scale, causing tick labels to be positioned at data values rather than pixel coordinates. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
…ts-suppressions.md Replace @ts-ignore with @ts-expect-error for untyped imports. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
…ndex.ts Must precede the 'from' clause to suppress the module-level import error. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
Iris Li (wpe1arhy)
left a comment
There was a problem hiding this comment.
Code review
2 comments on the TypeScript migration. Both are about the public/runtime contract rather than the mechanical JS→TS conversion, which looks clean.
🤖 Generated with Claude Code
# Conflicts: # packages/backpack-web/src/bpk-component-barchart/src/BpkBarchart.stories.tsx
Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
- Delete orphaned customPropTypes.ts and its test — no longer imported by any component after the TS migration - Replace [key: string]: unknown index signature on BpkBarchartProps with Omit<SVGProps<SVGSVGElement>, 'width' | 'height'> to restore excess-property checks, matching the pattern used by BpkChartAxis and BpkBarchartBars - Add dev-mode console.warn in componentDidMount to preserve the runtime validation that customPropTypes provided: warns if a data point is missing the xScaleDataKey or yScaleDataKey field (TypeScript cannot catch this as the keys are dynamic strings) Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
- Split the loose hybrid Scale type into BandScale/ContinuousScale union
with 'bandwidth' in scale narrowing, so round()/paddingInner/paddingOuter
are only required where they actually exist (d3 band scales) and the
call signature no longer lies about always returning a number.
- Remove the orphaned customPropTypes runtime validator and its test now
that BpkBarchart/BpkChartDataTable no longer import it.
- Replace the open `[key: string]: unknown` index signature on
BpkBarchartProps with Omit<SVGProps<SVGSVGElement>, ...> & {...}, matching
the pattern used by BpkBarchartBars/BpkChartAxis/BpkChartGridLines.
- Restore xAxisLabel/yAxisLabel as required props on BpkBarchartProps and
BpkChartDataTable's Props — they were PropTypes.string.isRequired /
non-optional Flow fields before the migration and were silently widened
to optional.
…art' into fix-pr-4755 # Conflicts: # packages/backpack-web/src/bpk-component-barchart/src/BpkBarchart.stories.tsx # packages/backpack-web/src/bpk-component-barchart/src/common-types.ts
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
The BandScale/ContinuousScale union in common-types.ts made scale.bandwidth/scale.ticks/scale.round/scale.paddingInner/scale.paddingOuter type errors under tsconfig.declaration.json's clean (non-incremental) build, since accessing a property that only exists on one union member requires narrowing (`'bandwidth' in scale`) rather than a direct truthy check. - utils.ts: type center()'s param as BandScale directly, since it's only ever called on band scales; drop the now-redundant bandwidth/round fallbacks. - BpkChartAxis.tsx / BpkChartGridLines.tsx: narrow with 'bandwidth' in scale and 'ticks' in scale before calling the corresponding methods. - BpkBarchartBars.tsx: type xScale/yScale as BandScale/ContinuousScale instead of the Scale union, since this component only ever receives one kind of each; default the possibly-undefined BandScale call result to 0. - BpkBarchart.tsx: type the xScale/yScale instance fields as BandScale/ContinuousScale to match, matching what's actually constructed in the constructor.
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
…AxisDomainExample stories The two RtlBarchart instances in CustomYAxisDomainExample were missing xAxisLabel/yAxisLabel, which the React19 CI job's clean pnpm install + `pnpm run typecheck` caught now that those props are required again (restored in an earlier commit to match the original PropTypes.isRequired contract).
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
…t-rest.md BpkBarchartBars spreads ...rest onto BarComponent (pre-existing behaviour), so it intentionally supports arbitrary props. Type it as `[rest: string]: any` with the inline reference required by decisions/inexact-rest.md, rather than `[key: string]: unknown`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4755 to see this build running in a browser. |
Summary
bpk-component-barchartfrom JavaScript to TypeScriptprop-typeswith TypeScript interfacesdefaultPropsto ES6 destructure defaults.jssource/test/story files to.tsx/.tsCloses #4742