Why is the .ts file extension used in Angular 2?

1

5 Answers

The .ts extension is used by TypeScript. Angular 2 does not really use the .ts extension. The code produced by the TypeScript compiler will be JavaScript with the .js extension. You can also use Dart as a development language that will still produce JavaScript code. If you feel like avoiding TypeScript or Dart, you can use plain JavaScript for developing Angular 2 applications.

With TypeScript you get some options that are not available to you in plain JavaScript. The definition of TypeScript from its web site is:

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript

To lean more about TypeScript visit its web site.

2

Angular 2 has the option to use multiple languages.

Languages are:

  1. JavaScript which uses .js extension (ES5 & ES6)
  2. TypeScript which uses .ts extension
  3. Dart which uses .dart extension
1

1) TypeScript - the biggest advantage point is its tooling set: auto completion, refactoring etc.

It helps large scale refactoring of projects risk free and easy, cost free.

2) TypeScript is a super set of JavaScript. So the advantage with this point is

  • Easy, efficient migration with less re-write.

3) Abstractions in TypeScript.

  • Loose coupling.
  • JavaScript doesn't support interfaces and it is difficult to set the boundaries where in the developers start depending on the concrete types instead of abstract types which leads to tight coupling.
  • Interfaces helps us to define API boundaries, reuse and nice code structure.

4) Last but not least, TypeScript provides you a lot without compromising the JavaScript ecosystem.

Because it was written on TypeScript, which is superset of JavaScript language. It is default language for development Angular2 application. But you still can use ES2015 (new version of JavaScript aka ES6) and Dart language.

You can write your Angular 2 application in ES5, EcmaScript 2015 or TypeScript. But the framework lends itself best to TypeScript.

TypeScript is a typed super set of JavaScript which has been built and maintained by Microsoft and chosen by the AngularJS team for development. The presence of types makes the code written in TypeScript less prone to run-time errors. In recent times, the support for ES6 has been greatly improved and a few features from ES7 have been added as well.

if you choose TypeScript to write code for your angular2 applications,then its uses .ts extension to save the file.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy