plantain-00 / type-coverage

A CLI tool to check type coverage for typescript code
MIT License
1.2k stars 43 forks source link

[feat] `skipLibCheck` like `tsconfig#compilerOptions` for typings from modules #100

Open JounQin opened 2 years ago

JounQin commented 2 years ago

Version(if relevant): 1.0.0

Environment(if relevant):

Code(if relevant):

import { workerData } from 'work_threads' // `workerData` is `any`
import type { StoreValue } from 'antd/lib/form/interface' // `StoreValue` is `any`

Expected:

Actual:

plantain-00 commented 2 years ago

I can't find a way to get whether an identifier's type(ts.Type) is from lib.

for example:

function foo(value: StoreValue) {
}
JounQin commented 2 years ago

Hmm... Interesting, how does TypeScript itself implement skipLibCheck? 🤣

plantain-00 commented 2 years ago

Typescript's skipLibCheck will ignore type error from lib files, type-coverage already do this.

for example, it will not report:

node_modules/antd/lib/form/interface.d.ts:1:1 StoreValue

Your case is more like:

import { Select } from 'antd'
const a: typeof Select = 1 // even though skipLibCheck is set, typescript will still report the error.

Maybe best solution is improve the lib's types.

JounQin commented 2 years ago

@plantain-00 I'm not using like that.

https://github.com/rx-ts/synckit/blob/main/src/index.ts#L6

src/index.ts:6:3: workerData
src/index.ts:113:41: message
src/index.ts:137:8: workerData
522 / 525 99.42%

Besides, the ignoreAsAssertion seems not working at https://github.com/rx-ts/synckit/blob/main/src/index.ts#L113

plantain-00 commented 2 years ago

src/index.ts:113:41: message comes from !.message, it's ignoreNonNullAssertion

JounQin commented 2 years ago

src/index.ts:113:41: message comes from !.message, it's ignoreNonNullAssertion

Ah, OK, thanks. So it would be better to show the detail reason.

JounQin commented 2 years ago

src/index.ts:113:41: message comes from !.message, it's ignoreNonNullAssertion

@plantain-00 Hmmm... Actually, I've already enabled ignoreNonNullAssertion at https://github.com/rx-ts/synckit/blob/main/package.json#L111

plantain-00 commented 2 years ago

the message is any, not ignoreNonNullAssertion and ignoreAsAssertion

JounQin commented 2 years ago

@plantain-00

I was expecting ignoreAsAssertion would ignore any as T.

plantain-00 commented 2 years ago

From ast's perspective, ignoreAsAssertion checks TypeAssertionExpression, any checks type of Identifier and ThisKeyword, It's important for them to keep single responsibility principle.

JounQin commented 2 years ago

Is there any chance to add a new option to ignore such usage? A lot of many any could be imported from 3rd-party packages or JSON.parse.

plantain-00 commented 2 years ago

Sure, PR is welcome. Like I commented before, I can't find a way to get whether an identifier's type(ts.Type) is from lib.