Overview
The@workspace/typescript-config package provides shared TypeScript configuration presets that ensure consistent type-checking, compilation settings, and best practices across all apps and packages in the monorepo.
Installation
The TypeScript config package is available as a workspace package:Available Configurations
The package provides several configuration presets tailored for different project types:base.json
Base configuration with strict TypeScript settings for all projects
react.json
Configuration optimized for React applications and libraries
nextjs.json
Configuration tailored for Next.js applications
node.json
Configuration for Node.js backend services
react-library.json
Configuration for React component libraries
Configuration Details
Base Configuration
Thebase.json provides foundational TypeScript settings:
Key Features
Key Features
- Strict Mode: Enabled for maximum type safety
- ES2022 Target: Modern JavaScript features
- No Unchecked Indexed Access: Prevents undefined access errors
- Isolated Modules: Each file can be transpiled independently
- JSON Module Resolution: Import JSON files with type safety
React Configuration
Extends the base config with React-specific settings:Key Features
Key Features
- JSX Support: Preserves JSX for bundler processing
- Bundler Module Resolution: Optimized for modern bundlers
- Web Worker Support: Includes Web Worker type definitions
- No Emit: Type-checking only, let bundler handle compilation
Next.js Configuration
Optimized for Next.js applications:Key Features
Key Features
- Next.js Plugin: Enables Next.js TypeScript features
- Bundler Resolution: Works with Next.js bundler
- JavaScript Support: Allows incremental TypeScript adoption
Usage in Apps
React App
For a React application (likeapps/react-vite):
tsconfig.json
Next.js App
For a Next.js application (likeapps/nextjs-app):
tsconfig.json
Node.js Service
For a Node.js backend service:tsconfig.json
React Library
For a React component library or shared package:tsconfig.json
Extending Configurations
You can layer multiple configurations for specific needs:tsconfig.json
Best Practices
Choose the Right Config
Select the configuration that matches your project type (React, Next.js, Node.js, or library).
Extend, Don't Copy
Always use
extends to inherit from the shared config instead of copying settings.Minimal Overrides
Only override settings when absolutely necessary. The shared configs are optimized for most use cases.
Configuration Philosophy
The TypeScript configurations in this package follow these principles:Strict Type Safety
Strict Type Safety
All configurations enable strict mode and additional safety checks like
noUncheckedIndexedAccess to catch potential runtime errors at compile time.Modern JavaScript
Modern JavaScript
Targeting ES2022+ ensures access to modern language features while maintaining broad compatibility.
Bundler Integration
Bundler Integration
React and Next.js configs use bundler module resolution, optimized for modern build tools like Vite and Turbopack.
Type-Only Compilation
Type-Only Compilation
Web configurations use
noEmit: true since bundlers handle the actual compilation, making TypeScript purely a type checker.Troubleshooting
Module Resolution Errors
Module Resolution Errors
If you encounter module resolution issues, ensure your
paths configuration in the local tsconfig.json matches your actual project structure.JSX Errors in React Projects
JSX Errors in React Projects
Make sure you’re extending the
react.json or nextjs.json config, which includes proper JSX settings.Strict Mode Errors
Strict Mode Errors
The configs enable strict mode by default. If migrating an existing project, you may need to address type errors incrementally.
