Update tsconfig.json presets for TS 5.0 (#7785)

This commit is contained in:
Erika 2023-07-26 15:13:22 +02:00 committed by Emanuele Stoppa
parent a6e5135765
commit 6f3180b1fa
3 changed files with 15 additions and 9 deletions

View file

@ -0,0 +1,5 @@
---
'astro': major
---
Update `tsconfig.json` presets with `moduleResolution: 'bundler'` and other new options from TypeScript 5.0. Astro now assumes that you use TypeScript 5.0 (March 2023), or that your editor includes it, ex: VS Code 1.77

View file

@ -5,14 +5,19 @@
"target": "ESNext", "target": "ESNext",
"module": "ESNext", "module": "ESNext",
// Enable node-style module resolution, for things like npm package imports. // Enable node-style module resolution, for things like npm package imports.
"moduleResolution": "node", "moduleResolution": "Bundler",
// Allow importing TypeScript files using their native extension (.ts(x)).
"allowImportingTsExtensions": true,
// Enable JSON imports. // Enable JSON imports.
"resolveJsonModule": true, "resolveJsonModule": true,
// Enable stricter transpilation for better output. // Enforce the usage of type-only imports when needed, which helps avoiding bundling issues.
"verbatimModuleSyntax": true,
// Ensure that each file can be transpiled without relying on other imports.
// This is redundant with the previous option, however it ensures that it's on even if someone disable `verbatimModuleSyntax`
"isolatedModules": true, "isolatedModules": true,
// Astro directly run TypeScript code, no transpilation needed. // Astro directly run TypeScript code, no transpilation needed.
"noEmit": true, "noEmit": true,
// Report an error when importing a file using a casing different from the casing on disk. // Report an error when importing a file using a casing different from another import of the same file.
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
// Properly support importing CJS modules in ESM // Properly support importing CJS modules in ESM
"esModuleInterop": true, "esModuleInterop": true,
@ -23,9 +28,6 @@
"paths": { "paths": {
"~/assets/*": ["src/assets/*"] "~/assets/*": ["src/assets/*"]
}, },
// TypeScript 5.0 changed how `isolatedModules` and `importsNotUsedAsValues` works, deprecating the later
// Until the majority of users are on TypeScript 5.0, we'll have to supress those deprecation errors
"ignoreDeprecations": "5.0",
// Allow JavaScript files to be imported // Allow JavaScript files to be imported
"allowJs": true "allowJs": true
} }

View file

@ -2,8 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig", "$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json", "extends": "./base.json",
"compilerOptions": { "compilerOptions": {
"strict": true, // Enable strict mode. This enables a few options at a time, see https://www.typescriptlang.org/tsconfig#strict for a list.
// Error when a value import is only used as a type. "strict": true
"importsNotUsedAsValues": "error"
} }
} }