Skip to content

Commit

Permalink
Update types in virtualized-lists so that they produce valid TS out…
Browse files Browse the repository at this point in the history
…put (#49263)

Summary:
Pull Request resolved: #49263

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D69308533

fbshipit-source-id: 36dd38a5bfce3b19eabcf04ef5f14e006d581bcd
  • Loading branch information
j-piasecki authored and facebook-github-bot committed Feb 11, 2025
1 parent 1cf4c84 commit b8e2bcd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
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

0 comments on commit b8e2bcd

Please sign in to comment.