Repository navigation
[bpk-component-infinite-scroll] Migrate to TypeScript - #4757
Conversation
Migrates bpk-component-infinite-scroll from JavaScript to TypeScript as described in #4744. - 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 #4744
|
Visit https://backpack.github.io/storybook-prs/4757 to see this build running in a browser. |
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-infinite-scroll from Flow/PropTypes-based JavaScript to TypeScript by introducing TS types for the HOC, data sources, tests, and stories.
Changes:
- Replaced Flow annotations and
prop-typeswith TypeScript types/interfaces across the component and tests. - Refactored
withInfiniteScrollinternals (config merging, own-prop omission) to be more TS-friendly. - Removed Flow-only type test file and adjusted IntersectionObserver polyfill usage.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/backpack-web/src/bpk-component-infinite-scroll/src/withInfiniteScroll.js | Introduces TS types for props/state and refactors HOC typing & prop pass-through. |
| packages/backpack-web/src/bpk-component-infinite-scroll/src/withInfiniteScroll-test.js | Removes PropTypes and adds TS annotations in tests. |
| packages/backpack-web/src/bpk-component-infinite-scroll/src/withInfiniteScroll-test.flow.js | Removes Flow type test file. |
| packages/backpack-web/src/bpk-component-infinite-scroll/src/intersection-observer.js | Updates IntersectionObserver polyfill wiring and adds TS-style assertion. |
| packages/backpack-web/src/bpk-component-infinite-scroll/src/accessibility-test.js | Removes PropTypes usage and adds TS annotations. |
| packages/backpack-web/src/bpk-component-infinite-scroll/src/DataSource.js | Removes Flow annotations and adds TS generics/types to DataSource listeners. |
| packages/backpack-web/src/bpk-component-infinite-scroll/src/DataSource-test.js | Adds TS annotations in DataSource tests. |
| packages/backpack-web/src/bpk-component-infinite-scroll/src/BpkInfiniteScroll.stories.js | Removes PropTypes, adds Storybook TS types, and adds explicit generics. |
| packages/backpack-web/src/bpk-component-infinite-scroll/index.js | Removes Flow header and keeps type re-export pattern. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Visit https://backpack.github.io/storybook-prs/4757 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4757 to see this build running in a browser. |
- Fix totalNumberElements under-count in onScrollFinished: use result.elementsToRender (post-concat) instead of the stale pre-concat elementsToRender parameter - Add .catch(console.error) to all fetchItems promise chains to prevent silent swallowing of dataSource rejections - Fix sentinel field declaration: remove contradictory ! assertion, initialize to null in constructor instead - Replace @ts-ignore with @ts-expect-error across 5 import suppressions in bpk-component-calendar, bpk-component-dialog, bpk-component-map, and bpk-component-infinite-scroll stories, per decisions/imports-ts-suppressions.md Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4757 to see this build running in a browser. |
|
|
||
| /* eslint-disable-next-line no-unused-vars */ | ||
| fetchItems(index: number, nElements: number): Promise<Array<T>> { | ||
There was a problem hiding this comment.
empty line should be deleted
|
|
||
| handleKeyPress: (e: SyntheticKeyboardEvent<HTMLButtonElement>) => void; | ||
|
|
||
| const OWN_PROP_KEYS = [ |
There was a problem hiding this comment.
OWN_PROP_KEYS is inferred as a bare string[], so it's completely decoupled from the Props interface. If a new prop is added to Props but not mirrored here, omit won't strip it and it'll silently leak into ComponentToExtend via {...(rest as any)} — with no compiler warning. Annotating it with Array at least catches typos and any renamed props at compile time:
| const OWN_PROP_KEYS = [ | |
| const OWN_PROP_KEYS: Array<keyof Props> = [ |
| }); | ||
| }) | ||
| .then((newState) => { | ||
| this.setState(newState as State); |
There was a problem hiding this comment.
React.Component.setState already accepts Partial<S>, so newState (typed Partial<State>) can be passed directly — the as State cast is unnecessary here. Worse, it suppresses a check that could be useful: if fetchItems were ever changed to return an object genuinely missing a required field, as State would silence the error. Suggest dropping the cast:
| this.setState(newState as State); | |
| this.setState(newState); |
| title: 'bpk-component-infinite-scroll', | ||
| component: WithInfiniteScrollMock, |
There was a problem hiding this comment.
Removing WithInfiniteScrollMock also dropped the component: field from meta, so the Docs page ArgTable will now be empty — a docs regression. The old mock's own comment noted it was only needed because HOC prop tables couldn't be generated in JS, and that it "does work in TS, so we can remove this once we migrate to TS". So this is the right time to point meta at the real component instead:
| component: WithInfiniteScrollMock, | |
| const meta: Meta<typeof InfiniteList> = { | |
| title: 'bpk-component-infinite-scroll', | |
| component: InfiniteList, | |
| decorators: [withScrollReset], | |
| }; |
There was a problem hiding this comment.
It's not showing up in the Product Storybook either.
There was a problem hiding this comment.
I checked production and the ArgTable is already missing there too, so this PR doesn't appear to introduce a docs regression here. Since the current published docs behave the same way, I don't think this should block the TS migration.
| if (onScrollFinished && result.isListFinished) { | ||
| onScrollFinished({ | ||
| totalNumberElements: elementsToRender.length, | ||
| totalNumberElements: (result.elementsToRender || elementsToRender || []).length, |
There was a problem hiding this comment.
This changes observable behaviour: when the final batch is non-empty but smaller than elementsPerScroll, onScrollFinished now reports the total including that batch (e.g. 7 items / elementsPerScroll=5 → fires with 7 instead of the old 5). The new value is correct, but it slips in as a migration side effect and tests only assert toHaveBeenCalled(). Please call it out in the PR description and add a value assertion to lock it in, e.g. expect(onScrollFinished).toHaveBeenCalledWith({ totalNumberElements: 7 }).
There was a problem hiding this comment.
Thanks for flagging this. I checked the direct BpkInfiniteScroll consumers listed on the Backpack versions page, including:
Skyscanner/zensearchSkyscanner/partner-portalSkyscanner/web-platformSkyscanner/packages-websiteSkyscanner/hotels-websiteSkyscanner/carhire-homepageSkyscanner/devex-web
My conclusion is:
onScrollFinishedis a behavior change, but I did not find any of the checked consumers relying on that callback in a way that would make this a breaking change..catch(console.error)does change error propagation, but the checked consumers already handle fetch failures in their own data source or request layers, usually by logging the error and showing local error UI. I did not find a consumer that depends onBpkInfiniteScrollpromise rejections as its primary monitoring signal.renderSeeMoreComponentis a type correction rather than a runtime break. The checked consumers already use({ onSeeMoreClick }: { onSeeMoreClick: () => void }) => ..., so this does not appear to break current usage.
So I think this PR introduces a few observable behavior/type changes, but I do not see evidence that it causes a breaking change for the repos currently consuming BpkInfiniteScroll. And it safe to mark as minor change.
- Remove stray empty line in DataSource.ts - Type OWN_PROP_KEYS as Array<keyof Props> to catch prop drift at compile time - Drop unnecessary `as State` cast from setState in componentDidMount - Restore component field in stories meta (fixes empty Docs ArgTable) - Strengthen onScrollFinished assertion to verify partial-batch total count Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4757 to see this build running in a browser. |
…State> React's setState types don't accept Partial<State> when State has required fields — restoring the `as State` cast to fix the TS error. Co-Authored-By: Claude Sonnet 4.6 (1M context) <[email protected]>
|
Visit https://backpack.github.io/storybook-prs/4757 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4757 to see this build running in a browser. |
|
Visit https://backpack.github.io/storybook-prs/4757 to see this build running in a browser. |
|
This PR does change some component behavior, but after checking the current BpkInfiniteScroll consumers, I don't see a path that would affect real users in a breaking way. The changes are mostly a behavior correction and type tightening, so I think it's reasonable to ship this as a minor release. Details:
|
Summary
bpk-component-infinite-scrollfrom JavaScript to TypeScriptprop-typeswith TypeScript interfacesdefaultPropsto ES6 destructure defaults.jssource/test/story files to.tsx/.tsCloses #4744