TypeScript doesn`t support IntersectionObserver v2 "delay" and "trackVisibility" options

20 Views Asked by At

During IntersectionObserver initialization, I encounter a TypeScript error that says "Object literal may only specify known properties, and 'trackVisibility' does not exist in type 'IntersectionObserverInit'.ts(2353)"

const observer = new IntersectionObserver(handleIntersection, {
  root: containerRef.current,
  threshold: 1.0,
  trackVisibility: true,
  delay: 300,
});

I couldn't figure out why TypeScript complains, as these options are outlined in the W3C specification: https://w3c.github.io/IntersectionObserver/v2/#dom-intersectionobserver-trackvisibility. The browser supports these features as well.

Here is my project`s tsconfig:

{
  "compilerOptions": {
    "target": "ES2020",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "noUnusedParameters": false,
    "noUnusedLocals": false,
    "jsx": "react-jsx",
    "experimentalDecorators": true,
    "types": ["node", "googlemaps"],
    "baseUrl": "."
  },
  "include": ["src"]
}
0

There are 0 best solutions below