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

Update virtualized-lists types to align them closer to TS definitions #49264

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update types in virtualized-lists so that they produce valid TS output
Summary: Changelog: [Internal]

Differential Revision: D69308533
  • Loading branch information
Jakub Piasecki authored and facebook-github-bot committed Feb 10, 2025
commit 5a1ff080ee8cb595c0638e7ef24f3810af50004d
4 changes: 2 additions & 2 deletions packages/virtualized-lists/Lists/StateSafePureComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default class StateSafePureComponent<
this._installSetStateHooks();
}

setState(
partialState: ?(Partial<State> | ((State, Props) => ?Partial<State>)),
setState<K: $Keys<State>>(
partialState: ?(Pick<State, K> | ((State, Props) => ?Pick<State, K>)),
callback?: () => mixed,
): void {
if (typeof partialState === 'function') {
Expand Down
6 changes: 3 additions & 3 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
(
this.props.renderScrollComponent ||
this._defaultRenderScrollComponent
)(scrollProps),
)(scrollProps) as ExactReactElement_DEPRECATED<any>,
{
ref: this._captureScrollRef,
},
Expand Down Expand Up @@ -1711,7 +1711,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
zoomScale,
};
if (this.state.pendingScrollUpdateCount > 0) {
this.setState(state => ({
this.setState<'pendingScrollUpdateCount'>(state => ({
pendingScrollUpdateCount: state.pendingScrollUpdateCount - 1,
}));
}
Expand Down Expand Up @@ -1871,7 +1871,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
_updateCellsToRender = () => {
this._updateViewableItems(this.props, this.state.cellsAroundViewport);

this.setState((state, props) => {
this.setState<'cellsAroundViewport' | 'renderMask'>((state, props) => {
const cellsAroundViewport = this._adjustCellsAroundViewport(
props,
state.cellsAroundViewport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export default class CellRenderer<ItemT> extends React.PureComponent<
},
};

static getDerivedStateFromProps(
props: Props<ItemT>,
prevState: State<ItemT>,
): ?State<ItemT> {
static getDerivedStateFromProps<StaticItemT>(
props: Props<StaticItemT>,
prevState: State<StaticItemT>,
): ?State<StaticItemT> {
if (props.item !== prevState.separatorProps.leadingItem) {
return {
separatorProps: {
Expand Down
28 changes: 6 additions & 22 deletions packages/virtualized-lists/Lists/VirtualizedListProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,17 @@ type OptionalProps = {
* `highlight` and `unhighlight` (which set the `highlighted: boolean` prop) are insufficient for
* your use-case.
*/
ListItemComponent?: ?(
| React.ComponentType<any>
| ExactReactElement_DEPRECATED<any>
),
ListItemComponent?: ?(React.ComponentType<any> | React.MixedElement),
/**
* Rendered when the list is empty. Can be a React Component Class, a render function, or
* a rendered element.
*/
ListEmptyComponent?: ?(
| React.ComponentType<any>
| ExactReactElement_DEPRECATED<any>
),
ListEmptyComponent?: ?(React.ComponentType<any> | React.MixedElement),
/**
* Rendered at the bottom of all the items. Can be a React Component Class, a render function, or
* a rendered element.
*/
ListFooterComponent?: ?(
| React.ComponentType<any>
| ExactReactElement_DEPRECATED<any>
),
ListFooterComponent?: ?(React.ComponentType<any> | React.MixedElement),
/**
* Styling for internal View for ListFooterComponent
*/
Expand All @@ -183,10 +174,7 @@ type OptionalProps = {
* Rendered at the top of all the items. Can be a React Component Class, a render function, or
* a rendered element.
*/
ListHeaderComponent?: ?(
| React.ComponentType<any>
| ExactReactElement_DEPRECATED<any>
),
ListHeaderComponent?: ?(React.ComponentType<any> | React.MixedElement),
/**
* Styling for internal View for ListHeaderComponent
*/
Expand Down Expand Up @@ -256,7 +244,7 @@ type OptionalProps = {
* <RefreshControl> component built internally. The onRefresh and refreshing
* props are also ignored. Only works for vertical VirtualizedList.
*/
refreshControl?: ?ExactReactElement_DEPRECATED<any>,
refreshControl?: ?React.MixedElement,
/**
* Set this true while waiting for new data from a refresh.
*/
Expand All @@ -270,7 +258,7 @@ type OptionalProps = {
/**
* Render a custom scroll component, e.g. with a differently styled `RefreshControl`.
*/
renderScrollComponent?: (props: Object) => ExactReactElement_DEPRECATED<any>,
renderScrollComponent?: (props: Object) => React.MixedElement,
/**
* Amount of time between low-pri item render batches, e.g. for rendering items quite a ways off
* screen. Similar fill rate/responsiveness tradeoff as `maxToRenderPerBatch`.
Expand All @@ -293,10 +281,6 @@ type OptionalProps = {
* chance that fast scrolling may reveal momentary blank areas of unrendered content.
*/
windowSize?: ?number,
/**
* The legacy implementation is no longer supported.
*/
legacyImplementation?: empty,
};

export type Props = {
Expand Down
2 changes: 1 addition & 1 deletion packages/virtualized-lists/Lists/VirtualizedSectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type OptionalProps<SectionT: SectionBase<any>> = {

type VirtualizedListProps = React.ElementConfig<typeof VirtualizedList>;

export type Props<SectionT> = {
export type Props<SectionT: SectionBase<any>> = {
...RequiredProps<SectionT>,
...OptionalProps<SectionT>,
...$Diff<
Expand Down