tsconfig icon indicating copy to clipboard operation
tsconfig copied to clipboard

Do not skipLibCheck

Open fregante opened this issue 4 years ago • 3 comments

I'm currently looking into using d.ts files as a way to declare some types using imports from libraries without risking to import the libraries themselves.

Example:

// my.d.ts
import eslint from "eslint"

export type ESLint = typeof esIint;

Did you catch that? TypeScript didn't. The .d.ts file above "passes" tsc validation but typeof eslint is spelled as typeof ESIINT.

Use skipLibCheck: false and it works:

Screen Shot 4

fregante avatar Sep 03 '21 13:09 fregante

But with lib skip off, checking becomes much slower... Is there any way to only check local files and ignore other packages? If not, might be worth opening a TS issue.

sindresorhus avatar Sep 03 '21 17:09 sindresorhus

Skip type checking of declaration files.

I had interpreted / remembered this option as meaning that types within dependencies weren't checked to be correct, only ones defined in ones own project, but the quote above is from the docs, so I agree, it's not good to have. See: https://www.typescriptlang.org/tsconfig#skipLibCheck

voxpelli avatar Sep 03 '21 20:09 voxpelli

Yeah I suppose the intended use of d.ts is to share types across libraries rather than locally, hence the skip LIB check.

In the past I enabled this flag (in an attempt) to fix some node_modules issues too, but I don't remember if it was effectively. Disabling it might bring those back (however I disabled it in a couple of large projects without issue)

fregante avatar Sep 04 '21 02:09 fregante

So – ran into this again in type-fest: https://github.com/sindresorhus/type-fest/pull/785

Whenever one handcrafts .d.ts files one should really keep skipLibCheck turned off.

voxpelli avatar Dec 15 '23 19:12 voxpelli