@workspace/typescript-config
The@workspace/typescript-config package provides shared TypeScript compiler configurations used across all applications and packages in the BE Monorepo. It ensures consistent type checking, module resolution, and build settings.
Overview
This package contains two TypeScript configuration presets:- base.json - Default configuration for general TypeScript projects
- node.json - Node.js-specific configuration with additional strictness
Installation
The package is already available in the monorepo workspace:Configuration Files
base.json
Location:packages/typescript-config/base.json:1
The base configuration provides a foundation for TypeScript projects with modern ES2022 features and strict type checking.
- ES2022 target - Modern JavaScript features
- NodeNext modules - Latest Node.js module resolution
- Strict mode - Full TypeScript strictness
- Declaration maps - Enables “Go to Definition” in editors
- DOM libraries - Browser API types included
- Index access checking - Prevents undefined array/object access
node.json
Location:packages/typescript-config/node.json:1
The Node.js configuration extends strictness with additional checks and Node-specific settings.
- ESNext target - Bleeding-edge JavaScript features
- Node.js types - Node.js API type definitions
- Unused code detection - Warns about unused variables/parameters
- Exact optional properties - Distinguishes undefined from missing properties
- Source maps - Debugging support
- JSX support - React JSX transform
- Verbatim module syntax - Preserves import/export as written
- Side effect import checking - Prevents unsafe imports
Usage
In Applications
Applications extend the Node.js configuration and add their own customizations: Example: Hono App Location:apps/hono/tsconfig.json:1
- Hono JSX configuration
- Bun runtime types
- Path aliases for imports
- Disabled declaration files (not needed for apps)
In Packages
Packages also extend the Node.js configuration: Example: Core Package Location:packages/core/tsconfig.json:1
Configuration Options Explained
Module Settings
module: “NodeNext”
Uses the latest Node.js module resolution algorithm, supporting both ESM and CommonJS.moduleResolution: “NodeNext”
Resolves modules using Node.js’s algorithm, respectingpackage.json exports and type: "module".
moduleDetection: “force”
Treats all files as modules (with implicitexport {}), preventing global scope pollution.
Strictness Settings
strict: true
Enables all strict type checking options:strictNullChecks- null/undefined must be explicitly handledstrictFunctionTypes- Function parameter types checked contravariantlystrictBindCallApply- Validates bind/call/apply argumentsstrictPropertyInitialization- Class properties must be initializednoImplicitAny- Prevents implicit any typesnoImplicitThis- Prevents implicit any on this
noUncheckedIndexedAccess: true
Array and object index access returnsT | undefined, catching potential runtime errors:
noUnusedLocals: true
Errors on unused local variables:noUnusedParameters: true
Errors on unused function parameters:exactOptionalPropertyTypes: true
Distinguishes betweenundefined and missing properties:
Module Syntax
verbatimModuleSyntax: true
Preserves import/export syntax exactly as written, preventing silent bugs:isolatedModules: true
Ensures each file can be transpiled independently (required for Babel, esbuild, swc):Output Settings
declaration: true
Generates.d.ts type definition files:
declarationMap: true
Generates.d.ts.map files, enabling “Go to Definition” to jump to source TypeScript files instead of .d.ts files in editors.
sourceMap: true
Generates.js.map files for debugging:
Best Practices
Extending Configurations
Always extend one of the base configurations instead of duplicating settings:Path Aliases
Define clear path aliases for better imports:Include/Exclude Patterns
Specify exactly what should be compiled:Runtime-Specific Types
Add appropriate type definitions for your runtime:Common Patterns
Application Configuration
Apps typically disable declaration generation and add path aliases:Package Configuration
Packages keep declarations for consumers:Testing Configuration
Test files may need relaxed strictness:Migration Guide
Adopting Strict Configurations
When migrating to stricter settings:- Enable one option at a time - Don’t enable all strict options at once
- Fix errors incrementally - Address errors in small batches
- Use type assertions sparingly - Fix underlying issues instead
- Add tests - Catch issues that TypeScript finds
Handling noUncheckedIndexedAccess
Add runtime checks for array/object access:Troubleshooting
Module Resolution Issues
Problem: “Cannot find module ‘@workspace/core‘“Solution: Check path mappings in tsconfig.json:
Type Import Errors
Problem: “‘X’ cannot be used as a value because it was imported using ‘import type‘“Solution: Use regular import for values, type import for types:
Declaration File Conflicts
Problem: Multiple declaration files for the same moduleSolution: Exclude build directories:
