Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GENERAL] [FIXED] VirtualizedList/FlatList: Stricter typing for onViewableItemsChanged #42773

Closed
wants to merge 2 commits into from

Conversation

miallo
Copy link
Contributor

@miallo miallo commented Jan 31, 2024

Summary:

The previous typing of FlatList and VirtualizedList did not convey any information on the type of the items passed in to onViewableItemsChanged, but instead the type was set to any. This PR adds the type information.

I set a default type any for thy ViewToken, because the type is exported and not having it would be a breaking change if that type is used. Like this it gracefully falls back to the default behavior of the any type.

Notice: I don't know how typing in "flow" works, but the same "issue" seems to be in there as well. Maybe someone with more flow experience can fix that as well:

export type ViewToken = {
item: any,

Changelog:

[GENERAL] [FIXED] - Add type information for items of VirtualizedList in onViewableItemsChanged signature
[GENERAL] [FIXED] - Add type information for items of FlatList in onViewableItemsChanged signature

Test Plan:

Without the changes, typecheck of the project was fine, but with the changes applied to the node_modules/react-native copy a type error was found:

$ npm run typecheck

> my-project@1.0.0 typecheck
> tsc --skipLibCheck

src/MyComponent.tsx:385:29 - error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'.
  Type 'string | number' is not assignable to type 'number'.
    Type 'string' is not assignable to type 'number'.

385                             viewableItems
                                ~~~~~~~~~~~~~
386                                 .filter(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jan 31, 2024
@facebook-github-bot
Copy link
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@NickGerleman merged this pull request in 35f5c3a.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants