Skip to content

[CLOV-102] BpkPrice Migrate JS to TypeScript#4521

Open
Vincent Liu (xiaogliu) wants to merge 2 commits into
mainfrom
xiaogliu/bpk-component-price-to-ts
Open

[CLOV-102] BpkPrice Migrate JS to TypeScript#4521
Vincent Liu (xiaogliu) wants to merge 2 commits into
mainfrom
xiaogliu/bpk-component-price-to-ts

Conversation

@xiaogliu
Copy link
Copy Markdown
Contributor

Summary

  • Convert the bpk-component-price package from JavaScript/Flow to TypeScript
  • Rename source/test files (.js.ts/.tsx) and the snapshot file so Jest still finds it
  • Replace propTypes + Flow Props with a typed Props export, re-exported from index.ts as BpkPriceProps
  • Props extends Omit<HTMLAttributes<HTMLDivElement>, 'className'> so native div attrs flow through ...rest while keeping className?: string \| null
  • SIZES / ALIGNS use as const so consumers get literal-typed values
  • Drop the now-unused @ts-expect-error suppressions on the BpkPrice and common-types imports in the stories file
  • No business-logic, JSX, or rendering changes — existing snapshots remain valid

Notes for reviewer

  • In BpkPrice-test.tsx, the existing const icon = NewWindowIcon passes a component reference (not a JSX element). Flow accepted this; TS does not. To keep the migration pure, I cast to ReactNode (as unknown as ReactNode) so the existing snapshots — which already render an empty <span class="bpk-price__icon ..."> because React silently does nothing with a function child — continue to match. Worth a follow-up to either drop the icon test cases or pass <NewWindowIcon /> and refresh the snapshots.

Test plan

  • npm run jest -- packages/backpack-web/src/bpk-component-price (4 suites, 92 tests, 64 snapshots all pass)
  • npx tsc --noEmit — no errors in bpk-component-price
  • npx eslint packages/backpack-web/src/bpk-component-price — no errors, no warnings

Convert the bpk-component-price package from JavaScript/Flow to
TypeScript. Replace prop-types and Flow Props with typed Props exports
and rename all source/test/snapshot files (.js -> .ts/.tsx). No
business-logic, JSX, or rendering changes - existing snapshots remain
valid.

- Rename index.js -> index.ts and re-export BpkPriceProps type
- Rename BpkPrice.js -> BpkPrice.tsx; type Props extends
  Omit<HTMLAttributes<HTMLDivElement>, 'className'> so native div props
  flow through ...rest while keeping className?: string | null
- Rename common-types.js -> common-types.ts; use `as const` so SIZES /
  ALIGNS export literal-typed values
- Rename test/accessibility-test/snapshot files; type the BpkPrice-test
  props variable as BpkPriceProps and cast the icon NewWindowIcon
  reference to ReactNode to preserve the existing (already-empty) icon
  span in snapshots
- Drop the now-unused @ts-expect-error suppressions on the BpkPrice and
  common-types imports in the stories file

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 21, 2026 04:11
@xiaogliu Vincent Liu (xiaogliu) added the minor Non breaking change label May 21, 2026
@xiaogliu Vincent Liu (xiaogliu) changed the title [BpkPrice] Migrate JS to TypeScript [CLOV-102] BpkPrice Migrate JS to TypeScript May 21, 2026
@skyscanner-backpack-bot
Copy link
Copy Markdown

Visit https://backpack.github.io/storybook-prs/4521 to see this build running in a browser.

The BpkPrice TS migration exposed two latent issues in card stories:
- Unused @ts-expect-error suppressions on BpkPrice imports (now typed)
- BpkCardV2 stories used SIZES.Large (capitalised), which compiled only
  because the SIZES import was untyped. With SIZES now `as const` the
  correct lowercase `large` key is enforced.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@skyscanner-backpack-bot
Copy link
Copy Markdown

Visit https://backpack.github.io/storybook-prs/4521 to see this build running in a browser.

@skyscanner-backpack-bot
Copy link
Copy Markdown

Browser support

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

Generated by 🚫 dangerJS against 15333db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor Non breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants