Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I haveread the FAQ and my problem is not listed.
Repro
- My scenario involves an ESLint plugin project in a monorepo with side-by-side versions of TypeScript
- Upgrade that project to use the latest
@typescript-eslint/parser
, with an indirect dependency on@typescript-eslint/types
- A file imported from
@typescript-eslint/types
fails to compile if your project is not using the very latest release of TypeScript. The error looks like:@typescript-eslint/types/dist/ast-spec.d.ts:781:5 - (TS1169) A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type.
Expected: We can solve this problem by upgrading the TypeScript dependency for our ESLint plugin project, while other monorepo projects continue to use the older TypeScript compiler that they target.
Actual: Upgrading TypeScript for the the plugin package does NOT upgrade the TypeScript import for@typescript-eslint/types
. As an indirect dependency, instead it accidentally picks up the older TypeScript version that was installed for a different project. This is because the package manager is not required to make any guarantees about the version (or even existence) oftypescript
for@typescript-eslint/types
, because it was not declared inpackage.json.
Specifically, thetypescript
package is referenced here:
import type { SyntaxKind } from 'typescript';
...but is only declared as a dev dependency here:
@typescript-eslint/types/package.json
"devDependencies":{"typescript":"*"}
This makestypescript
into aphantom dependency, which is an incorrect practice when using a package manager with a modern node_modules layout.
Suggested fix
- Add
typescript
to thepeerDependencies
section for@typescript-eslint/types
(maybe as an optional peer dependency if we are lazy), OR - Rework
ast-spec.d.ts
so that it does not rely on imports fromtypescript
It's possible to work around this problem using hacks, but those hacks would need to be applied to each project in this situation that somehow indirectly depends on@typescript-eslint/types
.
Versions
package | version |
---|---|
@typescript-eslint/types | 4.28.2 |
TypeScript | 3.9.x and4.3.x |
ESLint | 7.30.0 |
node | 12.20.1 |