A Namespace-Based Approach to Organizing TypeScript Code

Netanel Basal
Netanel Basal
Published in
Apr 17, 2022

I like to have a types file for each package that manages the types related to it for my applications. With Typescript namespaces, we can create a clean and well-organized types file.

For example, if we have a todos package in our application, we’ll create a todos.types file:

Now we can use it in the application:

Ultimately, it comes down to personal preference. It’s cleaner, more organized, and autocomplete is an added benefit.

Follow me on Medium or Twitter to read more about Angular and JS!

--

--

Netanel Basal
Netanel Basal

Written by Netanel Basal

A FrontEnd Tech Lead, blogger, and open source maintainer. The founder of ngneat, husband and father.

Responses (1)