gustavopch / tsc-files

A tiny tool to run `tsc` on specific files without ignoring tsconfig.json
MIT License
233 stars 49 forks source link

Different results from `tsc` #54

Closed JoshWhite closed 1 year ago

JoshWhite commented 1 year ago

Hi, I'm getting different errors when running tsc compared with tsc-files.

I get this when running tsc from root (this is what I expected):

> vite-test@0.0.0 tsc
> tsc

src/routes/Posts.tsx:31:23 - error TS7006: Parameter 'post' implicitly has an 'any' type.

31           {posts.map((post) => (
                         ~~~~

Found 1 error in src/routes/Posts.tsx:31

And this when running tsc-files in a git precommit hook:

✔ Preparing lint-staged...
❯ Running tasks for staged files...
  ❯ package.json — 9 files
    ✔ src/**/*.{js,jsx,ts,tsx,json,css,scss,md} — 4 files
    ❯ src/**/*.{js,jsx,ts,tsx} — 4 files
      ✔ eslint --cache --fix
      ✖ tsc-files --noEmit --pretty [FAILED]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ tsc-files --noEmit --pretty:
src/components/Page/Page.tsx:2:18 - error TS2307: Cannot find module '../../logo.svg' or its corresponding type declarations.

2 import logo from "../../logo.svg";
                   ~~~~~~~~~~~~~~~~

src/components/Page/Page.tsx:4:20 - error TS2307: Cannot find module './Page.module.css' or its corresponding type declarations.

4 import styles from "./Page.module.css";
                     ~~~~~~~~~~~~~~~~~~~

src/features/counter/Counter.tsx:12:20 - error TS2307: Cannot find module './Counter.module.css' or its corresponding type declarations.

12 import styles from "./Counter.module.css";
                      ~~~~~~~~~~~~~~~~~~~~~~

src/routes/Posts.tsx:31:23 - error TS7006: Parameter 'post' implicitly has an 'any' type.

31           {posts.map((post) => (
                         ~~~~

Found 4 errors in 3 files.

Errors  Files
     2  src/components/Page/Page.tsx:2
     1  src/features/counter/Counter.tsx:12
     1  src/routes/Posts.tsx:31
husky - pre-commit hook exited with code 1 (error)

Any idea why it's throwing the extra errors?

My tsconfig.json looks like this, if it helps:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"]
}
gustavopch commented 1 year ago

Same as https://github.com/gustavopch/tsc-files/issues/20. Check the comments for the explanation and workaround.