fix(kit): improve defaults in generated `tsconfig.json` (#27485)

This commit is contained in:
Daniel Roe 2024-06-07 21:08:57 +01:00 committed by GitHub
parent 9f24bc6386
commit af65d59678
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 28 deletions

View File

@ -292,7 +292,7 @@ const { data, error, execute, refresh } = await useFetch('/api/users')
<template> <template>
<div> <div>
<p>{{ data }}</p> <p>{{ data }}</p>
<button @click="refresh">Refresh data</button> <button @click="() => refresh()">Refresh data</button>
</div> </div>
</template> </template>
``` ```

View File

@ -122,28 +122,44 @@ export async function _generateTypes (nuxt: Nuxt) {
.map(m => getDirectory(m.entryPath)), .map(m => getDirectory(m.entryPath)),
) )
// https://www.totaltypescript.com/tsconfig-cheat-sheet
const tsConfig: TSConfig = defu(nuxt.options.typescript?.tsConfig, { const tsConfig: TSConfig = defu(nuxt.options.typescript?.tsConfig, {
compilerOptions: { compilerOptions: {
/* Base options: */
esModuleInterop: true,
skipLibCheck: true,
target: 'es2022',
allowJs: true,
resolveJsonModule: true,
moduleDetection: 'force',
isolatedModules: true,
verbatimModuleSyntax: true,
/* Strictness */
strict: nuxt.options.typescript?.strict ?? true,
noUncheckedIndexedAccess: nuxt.options.future?.compatibilityVersion === 4,
forceConsistentCasingInFileNames: true, forceConsistentCasingInFileNames: true,
noImplicitOverride: true,
/* If NOT transpiling with TypeScript: */
module: 'preserve',
noEmit: true,
/* If your code runs in the DOM: */
lib: [
'es2022',
'dom',
'dom.iterable',
],
/* JSX support for Vue */
jsx: 'preserve', jsx: 'preserve',
jsxImportSource: 'vue', jsxImportSource: 'vue',
target: 'ESNext', /* remove auto-scanning for types */
module: 'ESNext',
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,
noImplicitThis: true,
esModuleInterop: true,
types: [], types: [],
verbatimModuleSyntax: true, /* add paths object for filling-in later */
allowJs: true,
noEmit: true,
resolveJsonModule: true,
allowSyntheticDefaultImports: true,
paths: {}, paths: {},
/* Possibly consider removing the following in future */
moduleResolution: nuxt.options.future?.typescriptBundlerResolution || (nuxt.options.experimental as any)?.typescriptBundlerResolution ? 'Bundler' : 'Node', /* implied by module: preserve */
useDefineForClassFields: true, /* implied by target: es2022+ */
noImplicitThis: true, /* enabled with `strict` */
allowSyntheticDefaultImports: true,
}, },
include: [ include: [
'./nuxt.d.ts', './nuxt.d.ts',

View File

@ -1,20 +1,29 @@
{ {
// https://www.totaltypescript.com/tsconfig-cheat-sheet
"compilerOptions": { "compilerOptions": {
"forceConsistentCasingInFileNames": true, /* Base options: */
"esModuleInterop": false, "esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true, "skipLibCheck": true,
"target": "ESNext", "target": "es2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"noImplicitAny": true,
"allowJs": true, "allowJs": true,
"noEmit": true,
"noUnusedLocals": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"types": [ "moduleDetection": "force",
"node" "isolatedModules": true,
"verbatimModuleSyntax": true,
/* Strictness */
"strict": true,
// TODO: enable noUncheckedIndexedAccess
// "noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"noImplicitOverride": true,
/* If NOT transpiling with TypeScript: */
"module": "preserve",
"noEmit": true,
/* If your code runs in the DOM: */
"lib": [
"es2022",
"dom",
"dom.iterable"
], ],
"paths": { "paths": {
"#app": [ "#app": [