Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS type check is checking my lib incorrectly when added it to an App project. #23448

Open
1 of 4 tasks
joel-daros opened this issue May 16, 2024 · 0 comments
Open
1 of 4 tasks

Comments

@joel-daros
Copy link

Current Behavior

I’m have a NX monorepo with 1 app (my-app) and 1 lib (products).

The products lib has the noUncheckedIndexedAccess tsconfig property set to false in its libs/products/tsconfig.json file.
The my-app app has the noUncheckedIndexedAccess tsconfig property set to true in its apps/my-app/tsconfig.json file.

In the products lib I have this component being exported:

export function Products() {
  const myArr = [1, 2, 3];
  const index: number = 0;
  const value = myArr[index];
  return (
    <div>
      {/* I don't need the optional operator because this project has noUncheckedIndexedAccess = false */}
      <h1>{value.toString()}</h1>
    </div>
  );
}

And I importing it to my-app:

import { Products } from '@nx-test/products';

export function App() {
  return (
    <div>
      <Products />
    </div>
  );
}

When I run tsc command to type check my-app it’s throwing an error:

pnpm exec tsc --project ./apps/my-app/tsconfig.app.json --noemit
libs/products/src/lib/products.tsx:11:12 - error TS18048: 'value' is possibly 'undefined'.

11       <h1>{value.toString()}</h1>
              ~~~~~


Found 1 error in libs/products/src/lib/products.tsx:11
  1. Why TS is type checking a file (libs/products/src/lib/products.tsx) that’s outside my-app?
  2. Why is it not respecting the products lib tsconfig.json file?

Yes, I have the "skipLibCheck": true in my tsconfig.base.json file.

Expected Behavior

Type checking should be executed only for the files of my-app and not for its dependency libraries.

GitHub Repo

https://github.com/joel-daros/nx-tsconfig-issue

Steps to Reproduce

  1. Clone the project
  2. pnpm install
  3. Run the tsc command for type checking: pnpm exec tsc --project ./apps/my-app/tsconfig.app.json --noemit

Nx Report

Report complete - copy this into the issue template

Node   : 20.11.1
OS     : darwin-x64
pnpm   : 9.1.0

nx (global)        : 18.1.2
nx                 : 18.3.4
@nx/js             : 18.3.4
@nx/eslint         : 18.3.4
@nx/workspace      : 18.3.4
@nx/eslint-plugin  : 18.3.4
@nx/react          : 18.3.4
@nx/vite           : 18.3.4
@nx/web            : 18.3.4
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin

Failure Logs

libs/products/src/lib/products.tsx:11:12 - error TS18048: 'value' is possibly 'undefined'.

11       <h1>{value.toString()}</h1>
              ~~~~~


Found 1 error in libs/products/src/lib/products.tsx:11

Package Manager Version

pnpm 9.1.0

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants