gkim795
gkim795

Reputation: 170

Is there a way to change tsconfig to ignore certain libraries?

My codebase is a mix of typescript + javascript. When importing a javascript library into a typescript library, i just use the // @ts-ignore. But i'm using this javascript library quite frequently and it's been tedious to constantly put //@ts-ignore on top of the import. Is there a way to globally ignore the non-ts libraries?

//@ts-ignore
import jsLibraryThing from "@jsLibraryThing"

Upvotes: 2

Views: 2175

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 250416

You can create a declaration file for this library that just exports any. This will allow you to import it without any error and the import will be typed as any so you can use it almost like in JS

// jsLibraryThing.d.ts
declare module '@jsLibraryThing' {
    const e: any;
    export default e
 }

//usage.ts
import jsLibraryThing from "@jsLibraryThing"
jsLibraryThing.something // all fine

Upvotes: 2

Related Questions