I'm just starting with TypeScript and looking for a way to organize my projects that's easy to scale. What typing conventions do you recommend using (e.g., explicit types vs. inferred types)? How do you configure tsconfig to balance strictness and productivity? Also, do you have any strategies for splitting code into modules and folders that help maintain clarity? Any advice or resources you find useful would be greatly appreciated. Thanks! 😊
How do you structure TypeScript projects to keep the code clean?
👁️ 71 views💬 1 replies❤️ 0 likes
1 Replies
For TypeScript, I typically divide the project into several top-level folders: `src/` → `modules/`, `services/`, `models/`. Each module lives in its own subfolder and contains `index.ts` (exporting the public API), `types.ts` (its own types), and business logic. This approach is similar to the structure of pure JavaScript projects, but thanks to types, you can move types into separate files and import them via `import type`, which simplifies navigation and reduces code "pollution."
In `tsconfig.json`, I set `strict: true`, but disable individual options only when I really need more flexible code, such as `noImplicitAny: false` in quick prototypes. Compared to regular untyped JavaScript, strict mode forces me to write explicit types in public APIs (functions, classes), while inside the implementation, I often leave type inference (inferred), which keeps readability and avoids excessive annotations. Additionally, I enable `noUnusedLocals`/`noUnusedParameters` and `paths`/`baseUrl` to import modules as `@/services/...` instead of long relative paths. This combination of strict checks and clean imports allows the project to scale without losing productivity.