Unverified Commit 0d4707d6 authored by Wang Guan's avatar Wang Guan Committed by GitHub

next/client/link: improve internal type annotation (#12468)

parent a4c98f41
......@@ -55,9 +55,9 @@ export type LinkProps = {
}
let observer: IntersectionObserver
const listeners = new Map()
const listeners = new Map<Element, () => void>()
const IntersectionObserver =
typeof window !== 'undefined' ? (window as any).IntersectionObserver : null
typeof window !== 'undefined' ? window.IntersectionObserver : null
const prefetched: { [cacheKey: string]: boolean } = {}
function getObserver() {
......@@ -72,13 +72,13 @@ function getObserver() {
}
return (observer = new IntersectionObserver(
(entries: any) => {
entries.forEach((entry: any) => {
entries => {
entries.forEach(entry => {
if (!listeners.has(entry.target)) {
return
}
const cb = listeners.get(entry.target)
const cb = listeners.get(entry.target)!
if (entry.isIntersecting || entry.intersectionRatio > 0) {
observer.unobserve(entry.target)
listeners.delete(entry.target)
......@@ -90,7 +90,7 @@ function getObserver() {
))
}
const listenToIntersections = (el: any, cb: any) => {
const listenToIntersections = (el: Element, cb: () => void) => {
const observer = getObserver()
if (!observer) {
return () => {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment