Overview
@zayne-labs/tsconfig provides battle-tested TypeScript configuration presets for various project types. Inspired by Matt Pocock’s TSConfig Cheat Sheet, these presets ensure proper compiler settings for your specific use case.
Installation
Choosing the Right Config
The first step is determining which configuration preset fits your project. Answer these questions:Are you using tsc to compile TypeScript?
If yes, choose from the
tsc presets.If no, you’re probably using a bundler (Vite, webpack, esbuild, etc.) - choose from the bundler presets.Does your code run in the DOM?
If yes, choose a
dom preset (includes browser APIs).If no, choose a no-dom preset (for Node.js, CLI tools, etc.).Using TypeScript Compiler (tsc)
If you’re usingtsc to turn your .ts files into .js files, use these presets:
- DOM Environment
- Non-DOM Environment
For code that runs in the browser:
Using a Bundler
If you’re using an external bundler (Vite, webpack, esbuild, Rollup, etc.), use these presets:- DOM Environment
- Non-DOM Environment
For code that runs in the browser:
Framework-Specific Configs
Some frameworks have specific TypeScript configuration requirements:Next.js
For Next.js projects:tsconfig.json
More framework-specific configs will be added as needed.
Customizing Your Config
You can extend the base config with your own compiler options:tsconfig.json
Common Use Cases
React with Vite
React with Vite
tsconfig.json
Next.js App
Next.js App
tsconfig.json
Node.js CLI Tool
Node.js CLI Tool
tsconfig.json
Library with Declaration Files
Library with Declaration Files
tsconfig.json
Monorepo Package
Monorepo Package
tsconfig.json
Multiple TSConfig Files
For complex projects, you might need multiple TypeScript configs:- App + Node Scripts
- Frontend + Backend
tsconfig.json (main app):tsconfig.node.json (build scripts):
Decision Tree
Use this flowchart to quickly find the right preset:Best Practices
Always extend a preset: Don’t start from scratch. The presets include carefully chosen defaults that work well together.
Recommended Additional Settings
tsconfig.json
Troubleshooting
Module resolution errors
Module resolution errors
Make sure your
moduleResolution is set correctly:Cannot find type definitions
Cannot find type definitions
Install the necessary type packages:
Path aliases not working
Path aliases not working
Ensure your bundler is configured to handle path aliases:Vite:
vite.config.ts
Next Steps
ESLint Setup
Configure ESLint with TypeScript support
Prettier Setup
Set up Prettier for consistent formatting
