Remove Modules
Before enabling TypeScript in Bridge, you should remove deprecated TypeScript modules:- Remove
@nuxt/typescript-build- Bridge enables the same functionality - Remove
@nuxt/typescript-runtimeandnuxt-ts- Nuxt 2 has built-in runtime support
package.json
Enable TypeScript
Set bridge.typescript
Enable TypeScript support in yournuxt.config:
nuxt.config.ts
Update tsconfig.json
If you are using TypeScript, you can edit yourtsconfig.json to benefit from auto-generated Nuxt types:
tsconfig.json
As
.nuxt/tsconfig.json is generated and not checked into version control, you’ll need to generate that file before running your tests. Add nuxi prepare as a step before your tests, otherwise you’ll see TS5083: Cannot read file '~/.nuxt/tsconfig.json'For modern Nuxt projects, we recommend using TypeScript project references instead of directly extending .nuxt/tsconfig.json.Path Resolution
Configure Aliases
If you need custom path aliases, configure them in yournuxt.config:
nuxt.config.ts
Type Checking
Bridge enables type checking during development and build:nuxt.config.ts
Auto-generated Types
Bridge automatically generates type definitions for:- Components
- Composables
- Layouts
- Middleware
- Plugins
- Pages
.nuxt/types/ and include:
components.d.ts- Component typesimports.d.ts- Auto-import typesmiddleware.d.ts- Middleware typeslayouts.d.ts- Layout types
Strict Type Checking
You can enable strict type checking for better type safety:tsconfig.json
Using TypeScript in Components
With Bridge, you can use TypeScript in your components:Typing Runtime Config
You can type your runtime config:Common Issues
Module Resolution Errors
If you see errors likeCannot find module '#imports':
- Make sure you’ve run
nuxi prepare - Check that
tsconfig.jsonextends.nuxt/tsconfig.json - Restart your TypeScript server
Build Errors
If you encounter build errors:- Clear the
.nuxtdirectory:rm -rf .nuxt - Regenerate types:
nuxi prepare - Rebuild your project:
nuxi build
Benefits of TypeScript in Bridge
- Type Safety - Catch errors at compile time
- Better IDE Support - Enhanced autocomplete and IntelliSense
- Refactoring - Safer code refactoring
- Documentation - Types serve as inline documentation
- Nuxt 3 Compatibility - Same TypeScript setup as Nuxt 3