Skip to main content
This guide covers TypeScript configuration and coding patterns used across the Bitwarden client applications.

TypeScript Configuration

The project uses a centralized TypeScript configuration in tsconfig.base.json that is extended by individual packages.

Compiler Options

Type Checking

Key settings:
  • strict: false - Strict mode is disabled at the base level
  • noImplicitAny: true - Must explicitly type variables (no implicit any)
  • Uses typescript-strict-plugin for gradual strict mode adoption per file

Module Configuration

  • Target: ES2016 for broad compatibility
  • Module: ES2020 for modern module features
  • Lib: Includes ESNext.Disposable for resource management

Decorator Support

Required for Angular dependency injection and decorators.

Path Mappings

The project uses extensive path mappings to enable clean imports across the monorepo:
Available path prefixes:
  • @bitwarden/common/* - Core shared logic
  • @bitwarden/angular/* - Angular-specific utilities
  • @bitwarden/auth/* - Authentication modules
  • @bitwarden/components - Component library
  • @bitwarden/vault - Vault-specific code
  • @bitwarden/platform - Platform abstractions
  • And many more (see tsconfig.base.json:20-74 for full list)

Build Configuration

TypeScript Patterns

Explicit Types

Required: Always specify types for function parameters and return values.

Avoid any

While @typescript-eslint/no-explicit-any is currently disabled, avoid using any types.

Member Accessibility

Per ESLint rules (@typescript-eslint/explicit-member-accessibility), omit public keyword:

Promises

Always await or handle promises (@typescript-eslint/no-floating-promises):

Unused Variables

Function arguments named _ or unused are allowed (@typescript-eslint/no-unused-vars):

Gradual Strict Mode

The project uses typescript-strict-plugin to enable strict mode on a per-file basis:
This allows gradual migration to full strict mode without breaking the entire codebase.

Import Best Practices

Use Path Mappings

Always prefer @bitwarden/* imports over relative paths:

Alphabetize Imports

Imports are automatically organized by ESLint (import/order):
Order:
  1. Built-in/external packages (alphabetically)
  2. @bitwarden/* packages (alphabetically)
  3. src/ relative imports (alphabetically)
  4. Blank lines between groups

Type Safety Tools

Running Type Checks

This runs type checking across the entire codebase using the test-types script.

ESLint Type-Aware Rules

Many ESLint rules require type information and use tsconfig.eslint.json:
This enables advanced rules like:
  • @typescript-eslint/no-floating-promises
  • @typescript-eslint/no-misused-promises
  • Type-aware import resolution

Common Patterns

Ternary Expressions

Ternary expressions in statements are allowed (@typescript-eslint/no-unused-expressions):

This Aliasing

Only self is allowed as an alias for this (@typescript-eslint/no-this-alias):

Next Steps