This package contains shared TypeScript configurations for the monorepo.
📖 Back to Main README
This package provides standardized TypeScript configurations that can be shared across all applications and packages in the monorepo. It ensures consistent type checking and compilation settings throughout the project.
A base configuration with:
- ES2022 target
- Strict type checking
- Modern module resolution
- Common compiler options
Configuration for React applications with:
- React JSX support
- Testing library types (vitest, jest-dom)
- Source file includes for tests and Storybook
- No output (uses noEmit from base)
Configuration for Node.js build tools and scripts with:
- Composite project support
- Synthetic default imports
- Node.js types
- ES2022 library (no DOM)
In your package's tsconfig.json:
{
"extends": "@repo/typescript-config/react.json",
"compilerOptions": {
// Your package-specific options
}
}This package automatically includes @total-typescript/ts-reset for enhanced TypeScript types. No additional setup is required!
Projects extending from these configurations automatically get improved type safety for:
Array.includes()andArray.indexOf()Object.keys()andObject.entries()JSON.parse()- And many other built-in JavaScript methods
The reset types are automatically included when you extend from any of our configurations.
This package provides centralized global TypeScript declaration files that are available across all projects in the monorepo without requiring individual package installations.
Global types are exported from the types/ directory and automatically included in all TypeScript projects that extend from our configurations. This eliminates the need to install type packages in every project.
The package includes several utility types available globally:
// Utility type to make specific keys required
type RequireKeys<T, K extends keyof T> = T & Required<Pick<T, K>>;
// Utility type to make specific keys optional
type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
// Deep partial - makes all properties optional recursively
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
// Extract value type from arrays
type ArrayElement<T> = T extends (infer U)[] ? U : never;
// Create union of object values
type ValueOf<T> = T[keyof T];
// Branded/nominal types
type Brand<T, U> = T & { __brand: U };Global environment variable types are also included:
// Available in all projects
process.env.NODE_ENV; // 'development' | 'production' | 'test'
process.env.VITE_API_BASE_URL; // string | undefined
process.env.VITE_TMDB_API_KEY; // string | undefinedTo add new global types that should be available across all projects:
- Create a new
.d.tsfile in thetypes/directory - Add a triple-slash reference in
types/index.d.ts:
/// <reference path="./your-new-types.d.ts" />Example custom global types file:
// types/api.d.ts
declare global {
interface ApiResponse<T = unknown> {
data: T;
success: boolean;
message?: string;
}
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
}
export {};For more complex configurations, you can extend and customize:
{
"extends": "@repo/typescript-config/react.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"declarationMap": true,
"sourceMap": true
},
"include": ["src/**/*", "types/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.stories.ts"]
}To ensure projects can access the global TypeScript declarations, configure your project's tsconfig.json:
{
"extends": "@repo/typescript-config/react.json",
"compilerOptions": {
"baseUrl": ".",
"typeRoots": ["../../packages/typescript-config/types", "./node_modules/@types"]
},
"include": ["src/**/*.ts", "src/**/*.tsx", "../../packages/typescript-config/types/**/*.d.ts"]
}Key Configuration Options:
typeRoots: Tells TypeScript where to look for type definitionsinclude: Explicitly includes the global type files in compilation- Path should be relative to your project's location in the monorepo structure
Turbo.js Integration:
If using environment variables in your global types, ensure they're declared in your turbo.json:
{
"globalEnv": ["NODE_ENV", "VITE_API_BASE_URL", "VITE_TMDB_API_KEY"]
}The configurations follow this inheritance pattern:
base.json
├── react.json
├── nextjs.json
└── node.json
- Target: ES2022 for modern JavaScript features
- Module: ESNext for latest module syntax
- Strict: Enabled for comprehensive type checking
- ESModuleInterop: Enabled for better module compatibility
- SkipLibCheck: Enabled for faster compilation
- ForceConsistentCasingInFileNames: Enabled for cross-platform compatibility
- JSX: React-jsx for modern JSX transform
- Lib: Includes DOM and DOM.Iterable for browser APIs
- ModuleResolution: Bundler for modern bundler compatibility
- AllowImportingTsExtensions: Enabled for .ts/.tsx imports
- ResolveJsonModule: Enabled for JSON imports
When adding new TypeScript configurations:
- Consider if it should extend base, react, or be standalone
- Test the configuration across different package types
- Update this README with any new configurations
- Consider backward compatibility
You can test configurations locally by running:
# From the root directory
pnpm check-types
# From this package directory
pnpm ts-validateThe global types system is designed around these principles:
- Centralization: All shared types live in one location (
packages/typescript-config/types/) - Zero Installation: Projects don't need to install type packages individually
- Automatic Distribution: Types are distributed through workspace references and
typeRoots - Modularity: New global types can be added without breaking existing projects
packages/typescript-config/
├── types/
│ ├── index.d.ts # Entry point, references all other type files
│ ├── reset.d.ts # TypeScript reset integration
│ └── global.d.ts # Global utility types and environment variables
├── base.json # Base TypeScript configuration
├── react.json # React-specific configuration
├── node.json # Node.js configuration
└── package.json # Package exports and type definitions
- Package Exports: The
package.jsonincludes properexportsandtypesfields - TypeScript Configuration: Projects include the types directory in
typeRootsandinclude - Workspace References: Leverages pnpm/npm workspace features for seamless integration
- Build-time Resolution: Types are resolved at TypeScript compilation time, not runtime
- Module resolution errors: Check if
moduleResolutionis set correctly for your bundler - JSX errors: Ensure the correct JSX transform is configured
- Import errors: Verify
esModuleInteropandallowSyntheticDefaultImportssettings - Path mapping: Use
baseUrlandpathsfor custom module resolution - Global types not found: Ensure
typeRootsincludes the correct path topackages/typescript-config/types - Environment variable errors: Add missing env vars to
globalEnvinturbo.json
- Check the TypeScript documentation
- Review the TypeScript compiler options
- Open an issue in the main repository
This package is designed to work with:
- TypeScript 5.x
- React 18.x
- Node.js 18+
- Modern bundlers (Vite, Webpack, etc.)
- base.json: For utility packages or Node.js tools
- react.json: For React applications and components
- nextjs.json: For Next.js applications
- node.json: For Node.js build tools and scripts
- Use
skipLibCheck: truefor faster compilation - Consider
incremental: truefor large projects - Use
tsBuildInfoFilefor build info caching