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.
WithallowAutomaticSingleRunInference: true
enabled in a medium-sized React monorepo,compilerOptions.types
no longer works as expected in one of our packages. My best guess is that the package is being linted using the wrongtsconfig
.
Repro
With this config:
/packages/components/tsconfig.json
{"extends":"../../tsconfig.json","include": ["./src/**/*"],"compilerOptions": {"types": ["segment-analytics"] }}
And this line of code:
window.analytics.track(process.env["FOO"]??"foo");
Expected behaviour
WithoutallowAutomaticSingleRunInference
,@typescript-eslint/no-unsafe-member-access
gives us exactly the error we'd expect:
Unsafe member access .env on an `any` value
That's because I didn't include"node"
incompilerOptions.types
, soprocess.env
is untyped.
Actual behaviour
WithallowAutomaticSingleRunInference: true
, it's a different story:
Unsafe member access .track on an `any` value
Oops. Somehowprocess.env
is typed, butwindow.analytics
is untyped. Both are incorrect; so clearly ourcompilerOptions.types
isn't being respected.
No project references. We do usepaths
but they're not involved in this specific situation AFAIK. Ourtsconfig.json
inheritance is straightforward; I've included more of our config info below.
This reliably reproduces both locally and in CI, so I'm reasonably confident it isn't an environment issue.
Happy to hear any ideas RE: how we might create a standalone repro or help debug the issue. Access to our private repo could be an option, too.
Additional Info
/tsconfig.json
{"compilerOptions": {"baseUrl":"./","esModuleInterop":true,"forceConsistentCasingInFileNames":true,"incremental":true,"isolatedModules":true,"jsx":"preserve","module":"ESNext","moduleResolution":"Node","noEmit":true,"noImplicitOverride":true,"noPropertyAccessFromIndexSignature":true,"noUncheckedIndexedAccess":true,"noUnusedLocals":true,"noUnusedParameters":true,"paths": {"@reach/router": ["./node_modules/@gatsbyjs/reach-router/es"],"@shopnishe/components": ["./packages/components/src"]// Our other internal packages },"skipLibCheck":true,"strict":true,"target":"ESNext" }}
/.eslintrc.cjs
module.exports={extends:"./.eslintrc.base.cjs",overrides:[{files:["*.ts","*.tsx"],parserOptions:{allowAutomaticSingleRunInference:true,tsconfigRootDir:__dirname,project:["./apps/*/tsconfig.json","./packages/*/tsconfig.json"],},extends:["plugin:@typescript-eslint/recommended-requiring-type-checking",],rules:{// Our typed TypeScript rules},},],};
/.eslintrc.base.cjs
module.exports={root:true,extends:["eslint:recommended","plugin:react/recommended","prettier",// Disables conflicting rules in above configs"plugin:react-hooks/recommended","plugin:eslint-comments/recommended","plugin:import/recommended","plugin:jsx-a11y/strict",],parser:"@babel/eslint-parser",parserOptions:{sourceType:"module",},env:{browser:true,es2020:true,node:true,},plugins:["simple-import-sort"],rules:{// Our base rules},overrides:[{// Make sure ESLint can see every possible Node/TypeScript filefiles:["*.cjs","*.js","*.jsx","*.mjs","*.ts","*.tsx"],},{files:["*.ts","*.tsx"],extends:["plugin:@typescript-eslint/recommended","plugin:import/typescript",],plugins:["eslint-plugin-tsdoc"],rules:{// Our non-typed TypeScript rules},},],settings:{// Our eslint-plugin-import settingsreact:{version:"detect",},},};
Versions
package | version |
---|---|
@typescript-eslint/typescript-estree | 5.9.0 |
TypeScript | 4.5.4 |
node | 16.13.1 |
Environment Info:Node version: v16.13.1npm version: v8.1.2Local ESLint version: v8.6.0 (Currently used)Global ESLint version: Not foundOperating System: linux 4.19.128-microsoft-standard