TypeScript
ts/isolated-modules
A Vite project's tsconfig sets isolatedModules or verbatimModuleSyntax, so code the bundler compiles file by file type-checks the same way.
drobnastatycznefe-typescript
Dlaczego
Vite (through esbuild or Oxc) compiles each file alone and never type-checks. Features that need the whole program, such as const enum or an import of a type without type, compile in tsc but break or leave stray imports in the bundle. Without the flag, the editor and tsc stay silent about them.
Poprawka
Add "verbatimModuleSyntax": true (which implies isolated modules and keeps imports exactly as written) or at least "isolatedModules": true, then write import type { User } from './types' for type-only imports. Run tsc --noEmit (or vue-tsc, svelte-check, astro check) in CI, since the build itself does not check types.
Przykłady
// bad
{ "compilerOptions": { "module": "esnext", "moduleResolution": "bundler", "strict": true } }
// good
{ "compilerOptions": { "module": "esnext", "moduleResolution": "bundler", "strict": true, "verbatimModuleSyntax": true } }Źródła
Fakty
- Identyfikator
ts/isolated-modules- Waga
- drobna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
project- Tylko w projektach z
typescriptvite- Uczy jej skill
fe-typescriptTypeScript- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain ts/isolated-modules