A comprehensive, production-ready TypeScript project template with essential development tools, linting, formatting, testing, and pre-commit hooks.
- TypeScript: Latest TypeScript with strict configuration
- ESLint: Comprehensive linting with TypeScript-specific rules
- Prettier: Automatic code formatting with consistent style
- Jest: Testing framework with TypeScript support
- Husky: Git hooks for automated code quality checks
- lint-staged: Run linters on staged files only
- VS Code: Optimized settings and recommended extensions
- Path Mapping: Clean imports with
@/aliases - npm Scripts: Convenient commands for common tasks
- Node.js (>= 16.0.0)
- npm (>= 8.0.0)
-
Clone the repository
git clone <your-repository-url> cd typescript-project-template
-
Install dependencies
npm install
-
Initialize Husky (if needed)
npm run prepare
-
Start development
npm run dev
typescript-project-template/ βββ .husky/ # Git hooks β βββ pre-commit # Pre-commit hook script βββ .vscode/ # VS Code configuration β βββ extensions.json # Recommended extensions β βββ settings.json # Workspace settings β βββ tasks.json # Build tasks βββ src/ # Source code β βββ types/ # TypeScript type definitions β β βββ common.ts # Common types β β βββ user.ts # User types β β βββ index.ts # Type exports β βββ utils/ # Utility functions β β βββ calculator.ts # Calculator class example β β βββ greeting.ts # Greeting utilities β β βββ helpers.ts # Helper functions β β βββ index.ts # Utility exports β βββ index.ts # Main entry point βββ tests/ # Test files β βββ calculator.test.ts # Calculator tests β βββ greeting.test.ts # Greeting tests βββ dist/ # Compiled output (auto-generated) βββ coverage/ # Test coverage (auto-generated) βββ .eslintrc.json # ESLint configuration βββ .gitignore # Git ignore rules βββ .prettierrc # Prettier configuration βββ .prettierignore # Prettier ignore rules βββ jest.config.js # Jest configuration βββ package.json # Project configuration βββ tsconfig.json # TypeScript configuration βββ README.md # This file
typescript-project-template/
βββ .husky/ # Git hooks
β βββ pre-commit # Pre-commit hook script
βββ .vscode/ # VS Code configuration
β βββ extensions.json # Recommended extensions
β βββ settings.json # Workspace settings
β βββ tasks.json # Build tasks
βββ src/ # Source code
β βββ types/ # TypeScript type definitions
β β βββ common.ts # Common types
β β βββ user.ts # User types
β β βββ index.ts # Type exports
β βββ utils/ # Utility functions
β β βββ calculator.ts # Calculator class example
β β βββ greeting.ts # Greeting utilities
β β βββ helpers.ts # Helper functions
β β βββ index.ts # Utility exports
β βββ index.ts # Main entry point
βββ tests/ # Test files
β βββ calculator.test.ts # Calculator tests
β βββ greeting.test.ts # Greeting tests
βββ dist/ # Compiled output (auto-generated)
βββ coverage/ # Test coverage (auto-generated)
βββ .eslintrc.json # ESLint configuration
βββ .gitignore # Git ignore rules
βββ .prettierrc # Prettier configuration
βββ .prettierignore # Prettier ignore rules
βββ jest.config.js # Jest configuration
βββ package.json # Project configuration
βββ tsconfig.json # TypeScript configuration
βββ README.md # This file# Start development server with hot reload
npm run dev
# Build the project
npm run build
# Build and watch for changes
npm run build:watch
# Check TypeScript types without emitting
npm run typecheck# Run ESLint
npm run lint
# Fix ESLint issues automatically
npm run lint:fix
# Format code with Prettier
npm run format
# Check if code is formatted
npm run format:check
# Run pre-commit checks manually
npm run pre-commit# Run tests
npm run test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage# Clean build directory
npm run clean
# Start the built application
npm startThe tsconfig.json is configured with:
- Strict mode: Enabled for maximum type safety
- Path mapping: Use
@/for clean imports fromsrc/ - Modern target: Compiles to ES2022
- Declaration files: Automatically generated
- Source maps: Enabled for debugging
ESLint is configured with:
- TypeScript-specific rules
- Prettier integration
- Import sorting
- Unused variable detection
- Test file overrides
Prettier enforces:
- Single quotes for strings
- Semicolons
- 2-space indentation
- Trailing commas (ES5)
- 80 character line width
Jest is set up with:
- TypeScript support via
ts-jest - Path mapping support
- Coverage collection
- Test environment: Node.js
import { greet } from '@/utils/greeting';
import { Calculator } from '@/utils/calculator';
import type { User } from '@/types/user';
// Use greeting utility
console.log(greet('World'));
// Use calculator
const calc = new Calculator();
const result = calc.add(5, 3);
console.log(`Result: ${result}`);
// Work with types
const user: User = {
id: 1,
name: 'John Doe',
email: 'john@example.com',
isActive: true,
};-
Create new utilities
// src/utils/myUtility.ts export function myFunction(): string { return 'Hello from my utility!'; }
-
Export from index
// src/utils/index.ts export * from './myUtility';
-
Add tests
// tests/myUtility.test.ts import { myFunction } from '../src/utils/myUtility'; describe('myFunction', () => { it('should return expected string', () => { expect(myFunction()).toBe('Hello from my utility!'); }); });
The template includes recommendations for essential VS Code extensions:
- TypeScript and JavaScript: Enhanced language support
- ESLint: Real-time linting
- Prettier: Code formatting
- Error Lens: Inline error display
- TODO Tree: Track TODO comments
- Code Spell Checker: Spell checking
Pre-configured settings include:
- Format on save
- Auto-fix ESLint issues
- Organize imports automatically
- Consistent indentation
- File exclusions for cleaner explorer
Automatically runs before each commit:
- Lint staged files: ESLint fixes
- Format staged files: Prettier formatting
- Type checking: Ensures no TypeScript errors
Edit .husky/pre-commit or package.json lint-staged configuration to modify the pre-commit workflow.
- Keep utilities in
src/utils/ - Define types in
src/types/ - Use barrel exports (
index.ts) for clean imports - Follow consistent naming conventions
- Use strict TypeScript configuration
- Prefer
interfaceovertypefor object shapes - Use
readonlyfor immutable data - Leverage utility types (
Partial,Pick,Omit)
- Write tests for all utilities and business logic
- Use descriptive test names
- Group related tests with
describeblocks - Test both happy paths and error cases
- Use path mapping (
@/) for internal imports - Organize imports: external, internal, relative
- Use explicit imports/exports when possible
# Clear TypeScript build info
npm run clean
npm run build# Check configuration
npm run lint
npm run format:check# Run manually to debug
npm run pre-commit# Run with verbose output
npm run test -- --verbose- Check the error messages carefully
- Ensure all dependencies are installed:
npm install - Clear caches:
npm run clean - Check VS Code problems panel
- Review configuration files for syntax errors
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Happy coding! π