Skip to content

Commit 295dc96

Browse files
committed
fix(*): types
1 parent d06e889 commit 295dc96

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

lib/ObserveBoundingClientRect.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class ObserveBoundingClientRect extends React.PureComponent<
3636
IProps,
3737
IState
3838
> {
39-
private tickId: number;
39+
private tickId?: number;
4040

4141
constructor(props: IProps) {
4242
super(props);
@@ -76,7 +76,9 @@ export default class ObserveBoundingClientRect extends React.PureComponent<
7676
}
7777

7878
componentWillUnmount() {
79-
cancelAnimationFrame(this.tickId);
79+
if (typeof this.tickId === 'number') {
80+
cancelAnimationFrame(this.tickId);
81+
}
8082
}
8183

8284
tick(updater: Function) {

lib/ViewportCollector.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export default class ViewportCollector extends React.PureComponent<IProps> {
149149
private dimensionsState: IDimensions;
150150
private lastSyncedScrollState: IScroll;
151151
private lastSyncedDimensionsState: IDimensions;
152-
private tickId: NodeJS.Timeout;
152+
private tickId?: number;
153153
private componentMightHaveUpdated: boolean;
154154
private resizeObserver: ResizeObserver | null;
155155

@@ -158,7 +158,7 @@ export default class ViewportCollector extends React.PureComponent<IProps> {
158158
this.state = {
159159
parentProviderExists: false,
160160
};
161-
161+
this.componentMightHaveUpdated = false;
162162
this.scrollState = createEmptyScrollState();
163163
this.dimensionsState = createEmptyDimensionState();
164164
this.lastSyncedDimensionsState = { ...this.dimensionsState };
@@ -202,7 +202,9 @@ export default class ViewportCollector extends React.PureComponent<IProps> {
202202
this.resizeObserver.disconnect();
203203
this.resizeObserver = null;
204204
}
205-
cancelAnimationFrame(this.tickId);
205+
if (typeof this.tickId === 'number') {
206+
cancelAnimationFrame(this.tickId);
207+
}
206208
}
207209

208210
tick = () => {

lib/ViewportProvider.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default class ViewportProvider extends React.PureComponent<
8383
experimentalSchedulerEnabled: false;
8484
};
8585
private listeners: IListener[] = [];
86-
private updateListenersTick: NodeJS.Timer;
86+
private updateListenersTick?: NodeJS.Timer;
8787

8888
constructor(props: IProps) {
8989
super(props);
@@ -93,7 +93,9 @@ export default class ViewportProvider extends React.PureComponent<
9393
}
9494

9595
componentWillUnmount() {
96-
clearTimeout(this.updateListenersTick);
96+
if (typeof this.updateListenersTick === 'number') {
97+
clearTimeout(this.updateListenersTick);
98+
}
9799
}
98100

99101
triggerUpdateToListeners = (
@@ -172,7 +174,9 @@ export default class ViewportProvider extends React.PureComponent<
172174
};
173175

174176
updateHasListenersState() {
175-
clearTimeout(this.updateListenersTick);
177+
if (typeof this.updateListenersTick === 'number') {
178+
clearTimeout(this.updateListenersTick);
179+
}
176180
this.updateListenersTick = setTimeout(() => {
177181
this.setState({
178182
hasListeners: this.listeners.length !== 0,

0 commit comments

Comments
 (0)