plantain-00 / type-coverage

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

[feature request] a new option to ignore `Non-null assertion operator` #80

Closed JounQin closed 3 years ago

JounQin commented 3 years ago

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator

Sometimes, we can just confirm the value is non null.

transform('async function main() {}', {
  filename: 'fast-async.test.js',
  presets: ['@1stg'],
})!.code

Expected:

Pass

Actual:

Fail

plantain-00 commented 3 years ago

It's duplicated as #62 Since it's more needed than I expected, I will add it in the next few days.

plantain-00 commented 3 years ago

v2.16.0 should support it.

JounQin commented 3 years ago

I tried but it seems not working. 😂

/Users/JounQin/Workspaces/GitHub/configs/tests/test.spec.ts:6:7: transform('async function main() {}', {
        filename: 'fast-async.test.js',
        presets: ['@1stg'],
      })!
109 / 110 99.09%
The type coverage rate(99.09%) is lower than the target(100%).
plantain-00 commented 3 years ago

Did you use --ignore-non-null-assertion?

JounQin commented 3 years ago

It should be ralted to cache. I used type-coverage --ignore-xxx before, and changed to use config settings in package.json after upgrading.

{
  "typeCoverage": {
    "atLeast": 100,
    "cache": true,
    "detail": true,
    "ignoreCatch": true,
    "ignoreFiles": "*.d.ts",
    "ignoreNonNullAssertion": true,
    "strict": true
  }
}

I tried to run type-coverage --ignore-non-null-assertion again, it works, and then run type-coverage no error too, but I doubt the cache is correct, so I decide to delete .type-coverage folder, now it should work as expected.

JounQin commented 3 years ago

@plantain-00 Are you going to check the problem of cache, or should I close this issue?

plantain-00 commented 3 years ago

I will check it in next few days, I don't have time now.

plantain-00 commented 3 years ago

In v2.16.1, it should work with --cache