Ignore TypeScript errors introduced by imported third-party packages

Viewed 485

I want to import a TypeScript file contained in a package (node_modules). The external file contains type errors. When I run TypeScript compiler without importing the file, no errors are reported. However, I need the file for both its content and type declarations. Whenever I import the file, the errors contained in the file are also being reported when I run the compiler.

I've tried to include only my src folder, exclude the external file, make compilerOptions.types an empty array, set compilerOptions.skipLibCheck to true and/or put //@ts-ignore at my imported place, but none of these helps.

Considering that the file is in node_modules and I don't have access to that library, I cannot go into the file and fix the error or just write //@ts-ignore in it, because all changes will be overwritten in the future.

For example,

//@ts-ignore
import IntersectSrc from 'vuetify/src/directives/intersect'

export function foo() {
    console.log("Hello World")
    IntersectSrc.inserted(document.createElement('div'), {})
}

export type InsertFunctionType = typeof IntersectSrc['inserted']

with the following tsconfig.json

{
  "compilerOptions": {
    "target": "ES2016",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules",
    "node_modules/vuetify/src/directives/intersect/index.ts"
  ]
}

reports error Property '_observe' does not exist on type 'HTMLElement' from node_modules/vuetify/src/directives/intersect/index.ts.

So my question is, are there any ways to ignore the errors introduced by importing third-party packages?

0 Answers
Related