Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.

[bpk-component-barchart] Migrate to TypeScript - #4755

Merged
Iris Li (wpe1arhy) merged 19 commits into
mainfrom
ts-migration/bpk-component-barchart
Jul 22, 2026
Merged

Iris Li (wpe1arhy) merged 19 commits into
mainfrom
ts-migration/bpk-component-barchart

Conversation

@gert-janvercauteren

Copy link
Copy Markdown
Contributor

Summary

  • Migrates bpk-component-barchart from JavaScript to TypeScript
  • Replaces prop-types with TypeScript interfaces
  • Converts defaultProps to ES6 destructure defaults
  • Removes Flow type annotations
  • Renames .js source/test/story files to .tsx/.ts

Closes #4742

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
Copilot AI review requested due to automatic review settings June 26, 2026 09:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts and 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.

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

skyscanner-backpack-bot Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Browser support

If this is a visual change, make sure you've tested it in multiple browsers.

Generated by 🚫 dangerJS against 6bb5250

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]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@gert-janvercauteren
Gert-Jan Vercauteren (gert-janvercauteren) marked this pull request as ready for review June 29, 2026 03:47
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

…ts-suppressions.md

Replace @ts-ignore with @ts-expect-error for untyped imports.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

…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]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@wpe1arhy Iris Li (wpe1arhy) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Vincent Liu and others added 2 commits July 21, 2026 14:51
# Conflicts:
#	packages/backpack-web/src/bpk-component-barchart/src/BpkBarchart.stories.tsx
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

- 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]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

- 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
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

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.
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

…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).
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

…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]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@wpe1arhy
Iris Li (wpe1arhy) merged commit 58b98ce into main Jul 22, 2026
15 checks passed
@wpe1arhy
Iris Li (wpe1arhy) deleted the ts-migration/bpk-component-barchart branch July 22, 2026 10:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

minor Non breaking change ts-conversion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bpk-component-barchart] Migrate to TypeScript

4 participants