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

Typescript reports 0 erros #382

Open
2 tasks done
PLkolek opened this issue Aug 10, 2024 · 5 comments
Open
2 tasks done

Typescript reports 0 erros #382

PLkolek opened this issue Aug 10, 2024 · 5 comments

Comments

@PLkolek
Copy link

PLkolek commented Aug 10, 2024

Describe the bug

After bootstrapping a Vite react-ts project and following vite-plugin-checker's "Getting Started" to set up Typescript checker, the checker seems to execute Typescript, but for some reason it doesn't detect any errors. I.e. running npm run build fails due to type errors, but npm run dev outputs [TypeScript] Found 0 errors. Watching for file changes.

I using WSL on Windows - maybe this is what matters?

Reproduction

  1. npm create vite@latest my-react-app -- --template react-ts
  2. cd my-react-app
  3. npm i vite-plugin-checker -D
  4. Import and use checker in vite.config.ts with typescript: true
  5. Introduce type error in src/App.tsx
  6. npm run dev

Expected behavior

Expected result: same error as when executing npm run build.

src/App.tsx:21:41 - error TS2345: Argument of type '(count: number) => string' is not assignable to parameter of type 'SetStateAction<number>'.
  Type '(count: number) => string' is not assignable to type '(prevState: number) => number'.
    Type 'string' is not assignable to type 'number'.

21         <button onClick={() => setCount((count) => "123")}>

Actual result: no errors detected.

  VITE v5.4.0  ready in 435 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help

[TypeScript] Found 0 errors. Watching for file changes.

System Info

System:
    OS: Linux 5.10 Ubuntu 20.04 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
    Memory: 5.04 GB / 7.69 GB
    Container: Yes
    Shell: 5.0.16 - /bin/bash
  Binaries:
    Node: 20.13.1 - ~/.nvm/versions/node/v20.13.1/bin/node
    npm: 10.5.2 - ~/.nvm/versions/node/v20.13.1/bin/npm
  npmPackages:
    vite-plugin-checker: ^0.7.2 => 0.7.2

Additional context

No response

Validations

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@PLkolek
Copy link
Author

PLkolek commented Aug 11, 2024

Ah I see now. The project generated by npm create vite@latest my-react-app -- --template react-ts uses references, and AFAIU this requires buildMode: true. As I haven't worked with TS for a longer while I missed the whole references thing, and did not know what --build flag means ("why would I need to build anything if I am just running a checker?!"). Maybe the docs could be more explicit when this flag is needed, or that some Vite templates need this "advanced" option?

@bungdanar
Copy link

Ah I see now. The project generated by npm create vite@latest my-react-app -- --template react-ts uses references, and AFAIU this requires buildMode: true. As I haven't worked with TS for a longer while I missed the whole references thing, and did not know what --build flag means ("why would I need to build anything if I am just running a checker?!"). Maybe the docs could be more explicit when this flag is needed, or that some Vite templates need this "advanced" option?

I am still confused, I also use react-ts template, where should I set the buildMode: true or add the --build flag? The vite-plugin-checker doesn't have buildMode option but enableBuild. I have already set enableBuild: true but it still show 0 errors when in the development mode.

@mice33
Copy link

mice33 commented Aug 28, 2024

Ah I see now. The project generated by npm create vite@latest my-react-app -- --template react-ts uses references, and AFAIU this requires buildMode: true. As I haven't worked with TS for a longer while I missed the whole references thing, and did not know what --build flag means ("why would I need to build anything if I am just running a checker?!"). Maybe the docs could be more explicit when this flag is needed, or that some Vite templates need this "advanced" option?

I am still confused, I also use react-ts template, where should I set the buildMode: true or add the --build flag? The vite-plugin-checker doesn't have buildMode option but enableBuild. I have already set enableBuild: true but it still show 0 errors when in the development mode.

| buildMode | `boolean` | `false` | Add [`--build`](https://www.typescriptlang.org/docs/handbook/project-references.html) to `tsc` flag, note that `noEmit` does NOT work if `buildMode` is `true` ([#36917](https://github.com/microsoft/TypeScript/issues/36917)) |

After adding buildMode: true, I fixed the issue.

@terrance456
Copy link

terrance456 commented Oct 14, 2024

Solution:

vite.config.ts file

 plugins: [
    checker({
      typescript: { buildMode: true },
    }),
  ]

@crcass
Copy link

crcass commented Nov 21, 2024

If you're starting a new Vite project, the default tsconfig.json doesn't seem to work. Updating the config to point to tsconfig.app.json seems to fix the problem for me.

export default defineConfig({
  plugins: [
    react(),
    checker({ 
      typescript: {
        tsconfigPath: './tsconfig.app.json'
      },
     })
  ],
})

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

No branches or pull requests

5 participants