plantain-00/type-coverage

Unexpected report on `String#replace`

Closed this issue · 13 comments

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

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

@plantain-00

My tsconfig:

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

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

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
  }
}

@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

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.

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

image

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

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

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

Close for now.

should be related to #101

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