Why does Angular 2 use the .ts file extension?
AngularTypescriptFile TypeAngular 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:
- JavaScript which uses .js extension (ES5 & ES6)
- TypeScript which uses .ts extension
- Dart which uses .dart extension
Solution 3 - Angular
- 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.
- TypeScript is a super set of JavaScript. So the advantage with this point is
- Easy, efficient migration with less re-write.
- 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.
- 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.