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

[bpk-component-infinite-scroll] Migrate to TypeScript - #4757

Merged
Vincent Liu (xiaogliu) merged 13 commits into
mainfrom
ts-migration/bpk-component-infinite-scroll
Jul 6, 2026
Merged

Vincent Liu (xiaogliu) merged 13 commits into
mainfrom
ts-migration/bpk-component-infinite-scroll

Conversation

@gert-janvercauteren

Copy link
Copy Markdown
Contributor

Summary

  • Migrates bpk-component-infinite-scroll 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 #4744

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
Copilot AI review requested due to automatic review settings June 26, 2026 09:23
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

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-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-types with TypeScript types/interfaces across the component and tests.
  • Refactored withInfiniteScroll internals (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.

@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 4335857

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor


/* eslint-disable-next-line no-unused-vars */
fetchItems(index: number, nElements: number): Promise<Array<T>> {

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.

empty line should be deleted


handleKeyPress: (e: SyntheticKeyboardEvent<HTMLButtonElement>) => void;

const OWN_PROP_KEYS = [

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.

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:

Suggested change
const OWN_PROP_KEYS = [
const OWN_PROP_KEYS: Array<keyof Props> = [

});
})
.then((newState) => {
this.setState(newState as State);

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.

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:

Suggested change
this.setState(newState as State);
this.setState(newState);

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.

updated in 6f9bdc1

title: 'bpk-component-infinite-scroll',
component: WithInfiniteScrollMock,

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.

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:

Suggested change
component: WithInfiniteScrollMock,
const meta: Meta<typeof InfiniteList> = {
title: 'bpk-component-infinite-scroll',
component: InfiniteList,
decorators: [withScrollReset],
};

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.

It's not showing up in the Product Storybook either.

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.

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,

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.

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 }).

@xiaogliu Vincent Liu (xiaogliu) Jul 3, 2026 •

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.

Thanks for flagging this. I checked the direct BpkInfiniteScroll consumers listed on the Backpack versions page, including:

  • Skyscanner/zensearch
  • Skyscanner/partner-portal
  • Skyscanner/web-platform
  • Skyscanner/packages-website
  • Skyscanner/hotels-website
  • Skyscanner/carhire-homepage
  • Skyscanner/devex-web

My conclusion is:

  • onScrollFinished is 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 on BpkInfiniteScroll promise rejections as its primary monitoring signal.
  • renderSeeMoreComponent is 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]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@xiaogliu

Copy link
Copy Markdown
Contributor

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:

I dug into the current BpkInfiniteScroll consumers listed on the Backpack versions page, including zensearch, partner-portal, web-platform, packages-website, hotels-website, carhire-homepage, and devex-web.

My takeaway is that this PR introduces a couple of observable behavior/type changes, but I did not find evidence of a breaking runtime change for the existing consumers:

  • onScrollFinished is now aligned with the actual rendered count, which is a behavior fix rather than a consumer-facing break.
  • .catch(console.error) changes how failed fetches are surfaced, but the consumers I checked already handle fetch errors in their own data-source/request layers, so they are not relying on BpkInfiniteScroll promise rejections as their main error signal.
  • The renderSeeMoreComponent type is narrower, but the current consumers already use the ({ onSeeMoreClick }: { onSeeMoreClick: () => void }) => ... shape.

So I think it is fair to call out these as behavior/type changes, but I don't see evidence that they are breaking changes for the repos currently consuming this component.

@kerrie-wu kerrie-wu 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.

LGTM

@xiaogliu
Vincent Liu (xiaogliu) merged commit 52389b3 into main Jul 6, 2026
16 checks passed
@xiaogliu
Vincent Liu (xiaogliu) deleted the ts-migration/bpk-component-infinite-scroll branch July 6, 2026 03:51
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-infinite-scroll] Migrate to TypeScript

4 participants