Skip to content

Conversation

danielroe
Copy link
Member

🔗 Linked issue

resolves #25789

📚 Description

This improves types for Nuxt apps (and also within the monorepo), in many cases following recommendations from https://www.totaltypescript.com/tsconfig-cheat-sheet.

The most potentially disruptive changes is enabling noUncheckedIndexedAccess. I've marked that it only be enabled for v4+ but would be willing to revisit that. It will likely throw up a lot of type warnings, but can easily be disabled, and is a better choice for a new project.

As the diff in the PR is a bit messy (tidying up the options by topic/section), here's a simplified version:

    compilerOptions: {
      forceConsistentCasingInFileNames: true,
      jsx: 'preserve',
      jsxImportSource: 'vue',
-     target: 'ESNext',
-     module: 'ESNext',
+     target: 'es2022',
+     module: 'preserve',
      moduleDetection: 'force',
      moduleResolution: nuxt.options.future?.typescriptBundlerResolution || (nuxt.options.experimental as any)?.typescriptBundlerResolution ? 'Bundler' : 'Node',
      skipLibCheck: true,
      isolatedModules: true,
      useDefineForClassFields: true,
      strict: nuxt.options.typescript?.strict ?? true,
+     noUncheckedIndexedAccess: nuxt.options.future.compatibilityVersion === 4,
+     noImplicitOverride: true,
+     lib: [
+       'es2022',
+       'dom',
+       'dom.iterable'
+     ],
      noImplicitThis: true,
      esModuleInterop: true,
      types: [],
      verbatimModuleSyntax: true,
      allowJs: true,
      noEmit: true,
      resolveJsonModule: true,
      allowSyntheticDefaultImports: true,
      paths: {},
    }

@pi0 are you up for a similar PR to nitro?

@danielroe danielroe requested a review from DamianGlowala June 7, 2024 16:13
Copy link

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

@danielroe danielroe marked this pull request as ready for review June 7, 2024 19:32
@danielroe danielroe merged commit af65d59 into main Jun 7, 2024
@danielroe danielroe deleted the fix/type-improvements branch June 7, 2024 20:08
@github-actions github-actions bot mentioned this pull request Jun 7, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add noUncheckedIndexedAccess to tsconfig.server.json and tsconfig.json
1 participant