Repository navigation
[bpk-component-map] Migrate to TypeScript - #4762
Conversation
Migrates bpk-component-map from JavaScript to TypeScript as described in #4749. - 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 #4749
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-map toward TypeScript by replacing Flow/PropTypes with TS types and updating stories/tests accordingly.
Changes:
- Removed Flow pragmas and
prop-types, introducing TypeScript types/interfaces. - Updated marker tests/snapshots for
data-testidand adjusted story typing. - Introduced/updated shared types (e.g.,
LatLong, libraries list) and some ref typing.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/backpack-web/src/bpk-component-map/src/withGoogleMapsScript.js | Replaces PropTypes/Flow with TS generics and library unions. |
| packages/backpack-web/src/bpk-component-map/src/themeAttributes.js | Adds TS annotations to theme attribute arrays. |
| packages/backpack-web/src/bpk-component-map/src/common-types.js | Removes PropTypes and keeps only TS LatLong type. |
| packages/backpack-web/src/bpk-component-map/src/snapshots/BpkIconMarker-test.js.snap | Updates snapshot to use data-testid. |
| packages/backpack-web/src/bpk-component-map/src/DefaultLoadingElement.js | Removes Flow pragma. |
| packages/backpack-web/src/bpk-component-map/src/BpkOverlayView.js | Migrates props typing from Flow/PropTypes to TS. |
| packages/backpack-web/src/bpk-component-map/src/BpkMap.stories.js | Removes PropTypes-based story helpers and adds TS types/meta. |
| packages/backpack-web/src/bpk-component-map/src/BpkMap.js | Replaces PropTypes/Flow with TS types and ref typing; adjusts region change payload. |
| packages/backpack-web/src/bpk-component-map/src/BpkIconMarkerBackground.js | Adds TS typings via SVGProps and optional flags. |
| packages/backpack-web/src/bpk-component-map/src/BpkIconMarkerBackground-test.js | Removes Flow pragma. |
| packages/backpack-web/src/bpk-component-map/src/BpkIconMarker.js | Replaces PropTypes/Flow with TS types and updates click handling. |
| packages/backpack-web/src/bpk-component-map/src/BpkIconMarker-test.js | Updates mock typing and switches to data-testid in test. |
| packages/backpack-web/src/bpk-component-map/src/BpkBasicMapMarker.tsx | Cleans up imports and uses TS types for LatLong. |
| packages/backpack-web/src/bpk-component-map/src/BpkBasicMapMarker-test.js | Adds mock typing similar to other tests. |
| packages/backpack-web/src/bpk-component-map/index.js | Removes Flow pragma. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Visit https://backpack.github.io/storybook-prs/4762 to see this build running in a browser. |
…ppressions.md Replace @ts-ignore with @ts-expect-error for untyped imports. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
…ts-suppressions.md Replace @ts-ignore with @ts-expect-error for bpk-storybook-utils untyped import. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
…ppressions - Fix @ts-expect-error position in calendar/index.ts (must precede the 'from' line) - Remove @ts-expect-error in BpkBasicMapMarker: BpkOverlayView and common-types are now TypeScript on this branch so suppressions are no longer needed. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4762 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4762 to see this build running in a browser. |
Iris Li (wpe1arhy)
left a comment
There was a problem hiding this comment.
Code review
1 issue on the onRegionChange callback contract. Reviewed with the Backpack multi-agent checklist.
🤖 Generated with Claude Code
| onDragEnd={() => { | ||
| if (ref && ref.current && onRegionChange) { | ||
| onRegionChange(ref.current.getBounds(), ref.current.getCenter()); | ||
| const mapBounds = ref.current.getBounds(); | ||
| const mapCenter = ref.current.getCenter(); | ||
| onRegionChange(mapBounds, { | ||
| latitude: mapCenter.lat(), | ||
| longitude: mapCenter.lng(), | ||
| }); | ||
| } |
There was a problem hiding this comment.
onRegionChange changes its center argument shape at runtime — not behaviour-preserving
On main, getCenter() returned a raw google.maps.LatLng (read via .lat()/.lng()), passed straight to onRegionChange. This PR converts it to { latitude, longitude }, so consumers calling .lat()/.lng() will break. (The old Flow type claimed LatLong but never delivered it — this is arguably a fix, not a no-op.)
Please call it out in the PR description, re-check the minor label, and add a value assertion locking in the new shape (see #4757).
Nit: mapBounds is still the raw object but typed as Bounds — only center was normalised.
There was a problem hiding this comment.
I have adjusted the PR and created tests for this.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
…r shape
Lock in the normalised { latitude, longitude } shape of the center argument
passed to onRegionChange so regressions are caught at the unit-test level.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4762 to see this build running in a browser. |
Summary
bpk-component-mapfrom JavaScript to TypeScriptprop-typeswith TypeScript interfacesdefaultPropsto ES6 destructure defaults.jssource/test/story files to.tsx/.tsBehaviour change:
onRegionChangecenter argument shapeOn
main,onRegionChangereceived a rawgoogle.maps.LatLngobject as its second argument (consumers had to call.lat()/.lng()on it). The old Flow type declaredLatLongbut the runtime value never matched.This PR normalises the value to
{ latitude, longitude }so the runtime shape actually matches the declaredLatLongtype. This is arguably a bug fix, but consumers calling.lat()/.lng()on the center argument will break. Theminorlabel covers this.Closes #4749