We get asked often why we chose to use TypeScript as our development language for the Patterns and Practices JSCore library. Why not just es6? The simplest answer is scalability. Read the longer answer below the fold.
So seriously, why TypeScript? Yes, TS has static typing but how does that help? When I say scalability I have two interlocking ideas in mind – team size and code size. Let’s look at each point, then we’ll bring it all together at the end.
The same thing applies as teams change members. Much easier to see what is happening with a new library when you can clearly see what information is being passed around. Code simply becomes easier to understand, both to new team members to to folks having to debug years old code.
Similar to team size, as code grows it becomes complex and harder to follow without static typing. Static typing allows us to partition blocks of code by saying “I don’t care what happens in that method, but I know I get back a Date”. I’ve encountered a method named “getExpiration”. Likely that returns a date? Nope, a string name of the week like “Tuesday”. We can argue the merits of that particular design decision, but static typing makes this obvious.
As code bases grow we as developers increasingly need to trust the other parts of our own and others libraries to do what we expect. This is solved by the concept of exposing interfaces which create a defined contract between caller and callee. What do we give and what we expect to get back is explicitly defined. TypeScript also makes inheritance explicit and understandable.
The modern programmer’s job is to solve problems and manage complexity. That’s it. Many of the problems we encounter are quite complex and static typing is a great tool in the chest to help us keep things simple. We can also package up that complexity behind interfaces and isolate parts of our application from others.
So Why Then?
As we looked at starting an open source project for the JSCore we needed to manage a team of N developers that is constantly in flux as well as a planned large code base. As outlined above, the advantages of TypeScript helps us with both things. Anyone can fork the library and more quickly understand what is happening. So we decided to bring these advantages to the SharePoint JS client development space. Not accidentally it also aligns with the product group’s decision when they were designing the new SharePoint Framework and allowed us to begin introducing TypeScript and related concepts to the community before the official announcement.