vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
66.72k stars 5.98k forks source link

New tsconfig of create-vite gives type errors if `.d.ts` files can not be generated #17638

Closed kasperpeulen closed 2 weeks ago

kasperpeulen commented 1 month ago

Describe the bug

This PR introduced new default values for the tsconfig.json created with create-vite: https://github.com/vitejs/vite/pull/15913

This PR uses TS references and sets composite: true in tsconfig.json: https://github.com/vitejs/vite/blob/167006e74751a66776f4f48316262449b19bf186/packages/create-vite/template-react-ts/tsconfig.app.json#L1-L9

The references feature uses .d.ts files when references reference each other. So declaration is forced to be set to true: https://www.typescriptlang.org/tsconfig/#declaration

This gives quite some extra TS errors. In storybook, *.stories.ts files are usually not written in a way that allows .d.ts files to be generated from them.

In a fresh storybook vite react project, users now get the following TS error:

Exported variable 'meta' has or is using name 'ButtonProps' from external module "src/stories/Button" 
but cannot be named.
ts(4023)

Reproduction

https://stackblitz.com/edit/github-nup1wj?file=src%2Fvite-env.d.ts

Steps to reproduce

Clone the stackblitz repro locally. As stackblitz is also broken by this PR.

The error will popup in your editor in Button.stories.tsx, but not when running tsc on the command line.

System Info

System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 55.66 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 1.19.1 - ~/.nvm/versions/node/v18.18.0/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
    pnpm: 9.1.4 - ~/.nvm/versions/node/v18.18.0/bin/pnpm
    bun: 1.1.12 - ~/.bun/bin/bun
  Browsers:
    Chrome: 126.0.6478.127
    Chrome Canary: 128.0.6583.0
    Safari: 16.4
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1
    vite: ^5.3.1 => 5.3.3

Used Package Manager

npm

Logs

No response

Validations

stackblitz[bot] commented 1 month ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.