The Anatomy of a Great Typescript Book

If I was to write a TypeScript book, I would aim it at web developers who have started using TS, but come from a JavaScript background and have now been put on a TS-based project.

I wouldn’t aim at a certain web framework like React, or Angular, but how a web developer can start to use all the more advanced features in TypeScript so they can write good, type-safe code for their application, no matter the framework they are using.

In this ‘book,’ I will cover briefly what TypeScript is and its aim. I think it is clear now what TypeScript is and what its original aim was, but if someone is coming to this ‘book’ without knowing anything about TS then a brief introduction is needed. Try to explain to someone who’d be asked or just started using TypeScript why it’s so good and why they should be using it over JavaScript.

I’d then move on to introduce Types, and the primitive types that you have in TS (string, number, boolean) then move on to how to define your Types and the various ways you can do this. How you can create Types from other Types, how to use the utility Types and build up the Types for your project. All the time I try to keep it framework agnostic but relate it to a web developer who is now working on a TS-based project for the first time. So they can see that there are primitive Types, but they aren’t all you have (not everything needs to be a string). How you can start to build your Types that are more descriptive and applicable to your application.

Then I’d start looking at classes and modules and how they can be used along with Types to create a common library that you can use within the components of the framework you are using whether it’s Angular, Vue or React. Building this library of domain-specific Types that describe the data of your application and how you can use classes and modules to structure this library.

After introducing this concept of building a library for your application, which is more domain-specific and provides the business logic your UI components need. I’d move on to using Generics and how they can improve the re-usability of this business logic library.

I found Generics in TypeScript a complex topic to understand, especially if you’ve come from something like JavaScript. They are a powerful concept to understand and to start making use of, when you do it takes the re-usability of your code to another level. I feel that as a web developer who has used a couple of UI frameworks, concepts like Generics and Type manipulation are features I know about but haven’t used much in my applications because so much is handled by the framework. If I learnt more about these advanced concepts of TypeScript they’d improve my code so much.

I would then start to finish the book by looking at the compiler, how it works, and how to make use of the TSConfig settings and compiler. Again through using UI frameworks a lot of the TS compiler settings are set up as part of the framework CLI tooling. Knowing more about this area can lead to more efficient code.

After all that I’d spend a little time looking at the various TypeScript libraries that are available which can be used along with the framework to improve Type safety and maintainability within an application. Libraries like ZOD and tRPC, for example.

Finally, I would then take this concept of learning to build an internal library of business logic for an application and go through how external libraries can be built that can be used to share business logic across multiple applications. If you are a web developer who works for an organisation who have more than an internal application that uses TypeScript and how using features like classes, modules and Generics a Type safe domain-based library can be built and used across all these applications.

I think the aim of this ‘book’ would be to show that, yes TypeScript is used by all the main web frameworks, but there is more to it than just writing the code behind your framework’s components. We learn a lot about frameworks but not so much about the language behind it

Thinking in Redux – a Review

I recently finished reading a great book all about Redux, which is the core pattern behind NgRx. The book is called Thinking In Redux by Nir Kaufman. In this book Nir goes through introducing the core concepts behind Redux, including Actions, Reducers and Middleware (which we call Effects in NgRx).

As Nir goes through the book not only does he explain really clearly what each of the core concepts are, but he goes through and breaks down each concept into subsections. For examples, Middlewares are divided in to different categories one for Core functionality, where the Middleware role is to handle a common piece of functionality that could be used over and over again within the Application, e.g handling an API request. Verses a middleware who’s role is to handle Routing Actions.

The book is divided into 8 main sections, the first section is about how to think using the Redux pattern. It’s a great introduction into Redux, it’s core concepts and how we can think about these concepts as we start planning the development of our apps.

The second section is all about Actions, what they are, how we should use them, how to program an application using this pattern and ways we can categories the different types of Actions we may have in a Redux application.

Then Nir moves on to patterns for routing Actions and transforming Actions, how we can use Middlewares/Effects and various approaches we can take when writing our middleware/Effects.

In the final sectionNir goes through some thoughts on a Redux project structure, naming conventions and some recommended reading. While in the NgRx world we have the naming convention set out for us, his ideas on project structure are interesting.

On the whole Thinking in Redux is a good book. It explains the main concepts and patterns behind Redux really well, it’s a short book so doesn’t take long to read. I would recommend it to anyone looking to understand Redux a bit better especially if you’ve just started using NgRx for your Angular application and you want to take your understanding of Redux a bit further.