plantain-00 / type-coverage

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

Unexpected report on `String#replace` #96

Closed JounQin closed 2 years ago

JounQin commented 2 years ago

Version(if relevant): 2.18.0

Environment(if relevant):

Code(if relevant):

const camelCase = (val: string) =>
  val.replace(/-([\da-z])/g, ([_, $0]) => $0.toUpperCase())

Expected:

No report

Actual:

scripts/build.ts:45:32: _
scripts/build.ts:45:35: $0
scripts/build.ts:45:43: $0
scripts/build.ts:45:46: toUpperCase
154 / 158 97.46%

See ts playground

plantain-00 commented 2 years ago

your string. replace's type definition is at lib.es2015.symbol.wellknown.d.ts, you can check whether your -p tsconfig.json contains ES2015.

JounQin commented 2 years ago

@plantain-00

My tsconfig:

{
  "extends": "@1stg/tsconfig/lib"
}

It is using "lib": ["ESNext"] inside.

plantain-00 commented 2 years ago

What I tried:

{
  "extends": "@1stg/tsconfig/lib" // no error from type-coverage and vscode's typescript@4.3.5
}
{
  "extends": "@1stg/tsconfig/lib",
  "compilerOptions": {
    "target": "es5" // errored from type-coverage and vscode's typescript@4.3.5
  }
}
{
  "extends": "@1stg/tsconfig/lib",
  "compilerOptions": {
    "target": "es5",
    "downlevelIteration": true // no error from type-coverage and vscode's typescript@4.3.5
  }
}
JounQin commented 2 years ago

@plantain-00 Wired, can you please try https://github.com/JounQin/remark-preset-prettier/tree/fix/esm for reproduction? (Branch fix/esm)

remove line https://github.com/JounQin/remark-preset-prettier/blob/fix/esm/scripts/build.ts#L45

yarn && yarn build && yarn typecov
plantain-00 commented 2 years ago

I remove the // type-coverage:ignore-next-line -- https://github.com/plantain-00/type-coverage/issues/96 and get

$ yarn typecov
yarn run v1.22.4
$ type-coverage
158 / 158 100.00%
type-coverage success.
✨  Done in 4.76s.
plantain-00 commented 2 years ago

Maybe your error comes from the cached result, try to delete .type-coverage and do it again.

JounQin commented 2 years ago

image

I've tried to delete .type-coverage a lot of times.🤣

JounQin commented 2 years ago

OK, I found that it results 100% on Node 14 while lower on Node 12.

JounQin commented 2 years ago

That is very weird, after reinstall node 12 via nvm install 12, there is no issue...

Close for now.

JounQin commented 2 years ago

...

See https://github.com/JounQin/remark-preset-prettier/runs/3328501669#step:8:29

Or https://github.com/JounQin/remark-preset-prettier/actions/runs/1130254010

All node versions fail.

JounQin commented 2 years ago

should be related to #101

JounQin commented 2 years ago

Sorry, it still error https://github.com/JounQin/remark-preset-prettier/runs/5740767638?check_suite_focus=true

JounQin commented 2 years ago

Maybe related to extends node_modules json with same name dir like privatenumber/get-tsconfig@532bee9 (#21)