✓ Use strict mode: "strict": true in tsconfig.json
✓ Enable noUncheckedIndexedAccess, noImplicitReturns
✓ No any types without explicit // @ts-expect-error comment with justification
✓ All function parameters and return types explicitly typed
✓ Use unknown instead of any when type truly unknown
✓ Prefer const over let, never use var
✓ Use async/await over raw promises (better error handling)
✓ Arrow functions for callbacks: array.map(x => x * 2)
✓ Template literals over string concatenation: `Hello ${name}`
✓ Destructuring for object/array access: const { id, name } = user
✓ Optional chaining: user?.address?.city instead of nested checks
✓ Nullish coalescing: value ?? defaultValue instead of ||
✓ Functional components over class components
✓ Hooks over HOCs or render props
✓ Component files ≤200 lines (split into smaller components)
✓ Props validated with TypeScript interfaces or Zod
✓ No inline functions in JSX (causes unnecessary re-renders)
✓ Use React.memo() for expensive components
✓ Custom hooks for reusable logic (prefix with use)
✓ Use ES modules (import/export) over CommonJS (require)
✓ Environment variables via process.env with validation (Zod)
✓ Async error handling with try/catch or error middleware
✓ Graceful shutdown (handle SIGTERM, SIGINT)
✓ Rate limiting on public API endpoints
import{z}from'zod';constUserSchema=z.object({email:z.string().email(),age:z.number().int().positive(),role:z.enum(['admin','user']),});typeUser=z.infer<typeofUserSchema>;// Validate API inputapp.post('/users',(req,res)=>{constresult=UserSchema.safeParse(req.body);if(!result.success){returnres.status(400).json({errors:result.error});}constuser:User=result.data;// Type-safe!});
✓ Test files alongside code: user.service.ts + user.service.test.ts
✓ Test naming: describe('UserService') → it('should throw error when email invalid')
✓ Use beforeEach for setup, avoid test interdependencies
✓ Mock external dependencies (APIs, database, file system)
✓ Test both success and error paths
✓ Coverage target: >80% for business logic
import{describe,it,expect,beforeEach}from'vitest';import{UserService}from'./user.service';describe('UserService',()=>{letuserService:UserService;beforeEach(()=>{userService=newUserService();});it('should create user with valid data',async()=>{constuser=awaituserService.create({email:'test@example.com',age:25,});expect(user.id).toBeDefined();expect(user.email).toBe('test@example.com');});it('should throw error when email invalid',async()=>{awaitexpect(userService.create({email:'invalid',age:25})).rejects.toThrow('Invalid email');});});
importexpress,{Request,Response,NextFunction}from'express';// Typed request handlerapp.get('/users/:id',async(req:Request<{id:string}>,res:Response)=>{constuser=awaituserService.findById(req.params.id);if(!user){returnres.status(404).json({error:'User not found'});}res.json(user);});// Error middlewareapp.use((err:Error,req:Request,res:Response,next:NextFunction)=>{logger.error(err);res.status(500).json({error:'Internal server error'});});