plantain-00 / type-coverage

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

Add an option to ignore unread ("evolving") anys #67

Closed danvk closed 3 years ago

danvk commented 3 years ago

Fixes(if relevant): #28

Checks

Test/demo file:

$ cat test.ts
let val;  // any
if (Math.random() < 0.5) {
  val = /hello/;  // any
  val  // RegExp
} else {
  val = 12;  // any
  val  // number
}
val  // number | RegExp

Without the new flag: lines 1, 3 and 6 are flagged as anys With the new flag: no errors are flagged

Anecdotally, here's the diff for my project:

54890 / 55533 98.84% Before
55110 / 55533 99.23% After

So this removed 220/643 of the issues flagged by type-coverage. I skimmed through many of these and they seemed fine.

This is a long-standing pattern that has been allowed in TS since version 2.1.

danvk commented 3 years ago

@plantain-00 let me know if you're comfortable with this change and how I should test it. I'm very open to suggestions on names for this flag.

plantain-00 commented 3 years ago

released in v2.14.0

danvk commented 3 years ago

Amazing, thanks @plantain-00!!