Why does Angular 2 use the .ts file extension?

AngularTypescriptFile Type

Angular Problem Overview


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

Angular Solutions


Solution 1 - Angular

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.

Solution 2 - Angular

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

Solution 3 - Angular

  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.

  1. TypeScript is a super set of JavaScript. So the advantage with this point is
  • Easy, efficient migration with less re-write.
  1. 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.
  1. Last but not least, TypeScript provides you a lot without compromising the JavaScript ecosystem.

Solution 4 - Angular

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.

Solution 5 - Angular

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIsmail HView Question on Stackoverflow
Solution 1 - AngularHuskeView Answer on Stackoverflow
Solution 2 - AngularCalvin WilkinsonView Answer on Stackoverflow
Solution 3 - AngularDhanaView Answer on Stackoverflow
Solution 4 - AngularMikki KobvelView Answer on Stackoverflow
Solution 5 - AngularHarish KView Answer on Stackoverflow