- Ngoc Huynh
If you’ve used languages like C or Fortran, you’ll be familiar with static typing, which lets you declare types for variables to ensure, for example, A is always an integer and C is always a string. While TypeScript’s type safety isn’t as comprehensive as, say, Fortran’s, the ability to define number, string, and Boolean types can significantly help with debugging code. There’s also the option of letting TypeScript infer types, reducing the risk of errors when, for example, you assign an object to a string without an appropriate conversion. If your code is adding two numbers together, TypeScript will assume the result is always a number.
Defining the types in a function call is key to creating the structure of an interface, helping make your code more object-oriented. You can specifically define function elements as interfaces, giving you the option of having more descriptive names in a function, while still notifying tools like IntelliSense of function requirements when checking a call.
If you’re using Java or C#, then the TypeScript (and ECMAScript 6) implementation of classes will look very familiar. You’ll create classes with constructors that define the types used in a method, and that use the familiar this to handle internal objects. You can extend classes using inheritance, adding features and overriding methods. Perhaps most interesting, there’s also support for generics, which can be used for both functions and interface — and help you deliver reusable functions.
If you want to work with TypeScript, you’ll find support in current releases of Visual Studio and in the new Visual Studio Code cross-platform editing tool. There’s also an online code playground on the TypeScript site, where you can try out code ideas or work through online tutorials.
Source : http://www.infoworld.com/