1

I recently updated the @types/jest package in my project from version 24.9.1 to version 29.4.0. However, I'm now encountering a parsing error in the index.d.ts file of the package itself, located in the node_modules/@types/jest directory. The error message is Parsing error: ']' expected.

enter image description here

I'm not sure if this issue is caused by my TypeScript version, which is 3.8.3, because when I tried the same update on a different project with the same TypeScript version, it worked fine.

Kevin Bryan
  • 1,846
  • 2
  • 22
  • 45

1 Answers1

1

The following type definition is broken in your version (3.8.3), because this new keyof-as syntax was introduced in TypeScript 4.1.

type Func = Function;
type NonFunctionPropertyNames<T> = keyof { [K in keyof T as T[K] extends Func ? never : K]: T[K] };

See: "TypeScript keyof returning specific type"

You will need to upgrade your TypeScript compiler to a version ≥ 4.1.

Test cases

Broken in version 3.8.3

https://www.typescriptlang.org/play?ts=3.8.3#code/C4TwDgpgBAYgrgOwMZQLy0U4BLA9ggbgChRIoA5feZHfABQCddIHRyBDAWwgGcAeACoA+NFADWEELgBmUAN5QA2gGko2BOMkyoAqOx46VAXSgQAHsAgIAJgeooA-FAQQAbhAZQAXFGVGfAsZQAL4EQA

Works in version ≥ 4.1

https://www.typescriptlang.org/play?ts=4.1.5#code/C4TwDgpgBAYgrgOwMZQLy0U4BLA9ggbgChRIoA5feZHfABQCddIHRyBDAWwgGcAeACoA+NFADWEELgBmUAN5QA2gGko2BOMkyoAqOx46VAXSgQAHsAgIAJgeooA-FAQQAbhAZQAXFGVGfAsZQAL4EQA

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132