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

feat(create-vite): stricter TS configs in templates #12604

Merged
merged 2 commits into from Apr 5, 2023
Merged

Conversation

ArnaudBarre
Copy link
Member

@ArnaudBarre ArnaudBarre commented Mar 26, 2023

I started with allowImportingTsExtensions and then realised some where not enough strict and not homogenous at all.
Changes:

  • Target
    • Set to ES2020 to match Vite default target, enable useDefineForClassFields because only implied if target > 2022. This avoid TS autocompleting new features that would not be widely supported like intl.formatRange or array.at. Probably we can bump some numbers for Vite 5 to include string.replaceAll and add ES2021.string to the list
    • Always include dom.iterable
  • Bundler mode
    • allowImportingTsExtensions and update template accordingly
    • remove allowSyntheticDefaultImports and allowSyntheticDefaultImports: Personally I don't like using a default export when the lib doesn't explicitly set one and expecting it to work because bundler are doing crazy amount of interop.
  • Linting
    • Using strict + noUnusedLocals + noUnusedParameters, I hope no debate here
    • noFallthroughCasesInSwitch is a better default because it's too easy to miss.
    • noPropertyAccessFromIndexSignature: I started using it recently and I quite like it. I'm hesitant to add it
    • noImplicitReturns: I stopped enabling this because TS correctly infer undefined on empty branches and it's annoying when having early return on callback code (like we do in Vite plugins for ex).
    • useUnknownInCatchVariables: could be added but it's really annoying to not be able to set the error type to AxiosError for ex.

Note: I did not touch the svelte config because it already extend the one from the svelte team (and I know they don't use TS the same way as I do at all)

@stackblitz
Copy link

stackblitz bot commented Mar 26, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@ArnaudBarre ArnaudBarre changed the title Update ts config feat(create-vite): stricter TS configs in templates Mar 26, 2023
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the options separation 👍

@patak-dev patak-dev merged commit 4ffaeee into main Apr 5, 2023
14 checks passed
@patak-dev patak-dev deleted the update-ts-config branch April 5, 2023 07:56
@nickmccurdy
Copy link
Contributor

nickmccurdy commented Jun 30, 2023

Why were explicit extensions added? I think users generally expect bundlers to be able to resolve basic extensions. As for TS files, TS does support importing .js files by default in modules, but not .ts as they're not standard modules.

@ArnaudBarre
Copy link
Member Author

ArnaudBarre commented Jul 8, 2023

The TS doesn't allow .ts was a strange move from the TS team thinking that people don't bundle code and in the meantime looking at bundling their own lib with esbuild...

This is now over with TS 5, and I really want all this resolution problems to go away so that's why I defaulted the config to use explicit extensions. This avoids a lot of syscall. Can't believe this video is 5 years old: https://www.youtube.com/watch?v=M3BM9TB-8yA

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

Successfully merging this pull request may close these issues.

None yet

4 participants