TypeScript is ECMAScript 6 (ES6) with optional typing.
Where TypeScript comes in to its own is in its optional typing. A typed language like Java, C# or Objective-C requires you to specify the type of the variable when declaring it.
Declaring a string in Java would look like:
String name = "Andrew";, in C#
string name = "Andrew"; and in Objective-C it’s
NSString name = "Andrew".
In TypeScript it would be:
var name: string = "Andrew". But with it being optional, it can be just plain
var name = "Andrew". In strictly typed languages you have to declare everything all the time, with TypeScript you don’t!
Having types in your script allows text editors and IDEs to give you intelligent hints quickly without having to run your code.
It also helps with autocompletion of your code too. Other text editors autocomplete based on the text written in your project files, it doesn’t know anything about the type of each variable so you may end up passing a similarly named variable in to a method call but it’s the wrong type of object. However with TypeScript, code editors can have a more intelligent approach and suggest more appropriate variables to pass in to a function call. It’s a real productivity boost. It’s almost as if the code is writing itself.
It also reduces the need to look up documentation so frequently since the code is annotated with the types needed for a method call or what will be returned from a method call.
Because of these productivity wins from cleaner ES6 code, autocompletion, and hinting from optional typing, TypeScript is being adopted in to major projects, like AngularJS 2.0 and Ionic Framework 2.0.
Typing (May) Be Coming to a Language Near You
Some programmers prefer dynamic typing, that is, you don’t have to declare the type when programming your code. Perhaps the reason is the code is less verbose. However, there seems to be a trend at the moment where many programming languages are converging on ideas, from generics, immutable variables, asynchronous programming, optional typing, and even intelligent compilers. Even the creator of Ruby, Yukihiro Matsumoto, said static typing could be coming to version 3.0.
Having typing in your code not only helps programmer productivity but also helps interpreters and compilers to optimize the running of your code.
Comments are closed.
Front End Web Design
User Experience (UX) Design
iOS Development with Swift
Python Web Development
Each is designed by our faculty of tech professionals to guide even a coding beginner to becoming a job-ready software developer armed with a professional portfolio of real-world projects. Try one out today with our free seven-day trial, and see if software development is for you.