plantain-00 / type-coverage

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

Coverage numbers appear to be wrong #17

Open sslotsky opened 5 years ago

sslotsky commented 5 years ago

Version(if relevant): 1.10.0

I have a large project that's 100% JavaScript, and we'd like to start converting to TS. I added this tool and a tsconfig.json, and I converted one small file to TypeScript. The result:

69198 / 80159 86.33%
type-coverage success.

My tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "jsx": "react",
    "target": "ES2015",
    "module": "commonjs",
    "noImplicitAny": true,
    "strictNullChecks": true,
    "removeComments": true,
    "skipLibCheck": true,
    "preserveConstEnums": true,
    "sourceMap": true,
    "moduleResolution": "node",
    "outDir": "dist"
  },
  "include": ["src/**/*.*"],
  "exclude": ["node_modules"]
}

How can it report such a high coverage ratio when only one of my files is typed?

plantain-00 commented 5 years ago

With allowJs, Typescript can get a collect type even it is a js file, for example:

var foo = 1 // foo is number

/**
 * @param {number} baz
 */
function bar(baz) { // baz is number
}

So it is possible.

sslotsky commented 5 years ago

Hmm, I see your point. This tool won't tell me how much of my code is type safe, i.e. how much of it will compile safely; it will only tell me how many of my identifiers have types that can be inferred.

abhieshekumar commented 10 months ago

@sslotsky have a similar setup as your project (Javascript files being migrated to TS). What approach did you folks use to get typescript coverage? Is there a way to include JS files in coverage and have their coverage percentage as 0 instead of what's reported by the tool?