Origins

TypeScript - Nothing but Upside

JavaScript is an accident of history - Story goes that Brendan Eich created it in 1995 over 10 days to enable scripting in Netscape Navigator. After 25+ years of evolution, it is a much better language but too many warts still remain.

For industrial strength webapps, JavaScript just doesn’t cut it. Many of the underlying issues are due its dynamic type pedigree.

A statically typed language as a superset of JavaScript is just a brilliant idea - wish I came up with it but Microsoft is just paying back their past transgressions.

While we know C and Java as statically typed languages, TypeScript is similar but different in the way it uses types. It uses duck typing which means as long as a Type matches the structure, there is no need to declare the type as a sub-type as you would in Java.

Combined with type inference, coding in TypeScript feels similar to JavaScript but with all the extra benefits.

TypeScript Benefits we cannot ignore

Static types

Types are just great. By defining all the variables as of specific type, code is guaranteed to be correct if program compiles. This is equivalent of creating many unit tests to verify each and every variable and its usage.

Type Inference

In Java or C, every variable must be declared with a type. However, TypeScript deduces the type based on the assigned value. For this reason, TypeScript is almost written like JavaScript and less typing is just better on fingers and clarity.

Tooling and Developer Experience (DX)

A good developer experience is a boon to productivity. A capable IDE like VSCode can show a lot of contextual information in TypeScript code due to the meta information available as types. Auto-suggestions and auto-completion are just wonderful productivity enhancing features.

Duck Typing

If something walks and quacks like a duck, its a duck! TypeScript types are like ducks. When expected value is of type Foo, any value matching Foo’s structure can be passed. This allows coders flexibility in type declaration promoting loose coupling.

// Here, Person value can be used wherever Employee is expected.  
// This is not possible in Java unless their relation is declared.

type Person = {
  name: string
  age: number
}

type Employee = {
  name: string
  age: number
  employeeId: string
}

Team communication

Let’s just say it - developers tends to document little. Other than choosing descriptive names, a defined Type reveals quite a bit about the program structure - making it easy to onboard new engineers and team communication.

Conclusion

TypeScript provides many benefits on top of JavaScript for long lasting production code. It does so without many pitfalls associated with traditional statically types languages.

As a software developer, my main worry is buggy production code. TypeScript goes a long way helping write clean and correct code that is a great start for further testing.

Almost all new and famous Node.js projects are now using TypeScript or moving to it. I’d advocate the same if you’re not already on that path. ProAutoma uses TypeScript across frontend and backend and we couldn’t more happier.

Get your ProAutoma Free Account to monitor your Website or API. 50K monthly checks are free, that is 5 sites checked every 5 minutes.

Try our Free API Tester tool to explore and test your APIs. All you need is a URL to get started.