plantain-00 / type-coverage

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

Parameter incorrectly flagged as any when type applied to whole function #82

Closed danvk closed 3 years ago

danvk commented 3 years ago

Version(if relevant): 2.16.0

Environment(if relevant):

Code(if relevant):

export const checkedFetch: typeof fetch = async (input, init) => {
  const r = await fetch(input, init);
  if (r.status !== 200) {
    throw new Error(`${r.status} ${r.statusText}`);
  }
  return r;
};

Expected:

The input and init params have types.

Actual:

type-coverage reports that they have any types.

You can see from this playground that the typeof fetch is sufficient to get contextual types for the function params:

image

plantain-00 commented 3 years ago

I can't reproduce it with --strict

17 / 17 100.00%

Maybe your tsconfig.json lib didn't include dom

danvk commented 3 years ago

This seems to be related to the issue from #83; I can reproduce this only if I add an exclude: [] section to my tsconfig.json.

yarn type-coverage --detail --strict -p tsconfig+exclude.json
yarn run v1.22.4
$ /Users/danvk/code/type-coverage-toy/node_modules/.bin/type-coverage --detail --strict -p tsconfig+exclude.json
/Users/danvk/code/type-coverage-toy/fetch.ts:1:50: input
/Users/danvk/code/type-coverage-toy/fetch.ts:1:57: init

Here's the setup, reusing this gist:

$ cat fetch.ts
export const checkedFetch: typeof fetch = async (input, init) => {
  const r = await fetch(input, init);
  if (r.status !== 200) {
    throw new Error(`${r.status} ${r.statusText}`);
  }
  return r;
};

$ tail tsconfig+exclude.json
    // "experimentalDecorators": true,        /* Enables experimental support for ES7 decorators. */
    // "emitDecoratorMetadata": true,         /* Enables experimental support for emitting type metadata for decorators. */

    /* Advanced Options */
    "skipLibCheck": true,                     /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true  /* Disallow inconsistently-cased references to the same file. */
  },
  "exclude": [
  ]
}
plantain-00 commented 3 years ago

v2.16.2 should fix this

danvk commented 3 years ago

fix confirmed, thanks @plantain-00!