- Angular UI Development with PrimeNG
- Sudheer Jonna Oleg Varaksin
- 448字
- 2021-07-15 17:32:54
TypeScript fundamentals
Angular 2 and higher is built with features of ECMAScript 2015/2016 and TypeScript. The new ECMAScript standards target evergreen browsers and helps to write more powerful, clean, and concise code. You can also use these features in any other less modern browsers with Polyfills such as core-js (https://github.com/zloirock/core-js). But, why do we need to use TypeScript?
TypeScript (http://www.typescriptlang.org) is a typed language and a super set of JavaScript developed by Microsoft. One can say that TypeScript is an advanced JavaScript with optional static typing. TypeScript code is not processed by browsers, it has to be translated into JavaScript by means of a TypeScript compiler. This translation is called compilation or transpilation. The TypeScript compiler transpiles .ts files into .js files. The main advantages of TypeScript are as follows:
- Types help you find and fix a lot of errors during development time. That means, you have less errors at runtime.
- Many modern ECMAScript features are supported out of the box. More features are expected according to the roadmap (https://github.com/Microsoft/TypeScript/wiki/Roadmap).
- Great tooling and IDE support with IntelliSense makes the coding a pleasure.
- It is easier to maintain and refactor a TypeScript application than one written in untyped JavaScript.
- Developers feel comfortable with TypeScript due to object-oriented programming patterns, such as interfaces, classes, enums, generics, and so on.
- Last but not least, Angular 2+ and PrimeNG are written in TypeScript.
It is also important to keep the following points in mind:
- The Typescript Language Specification says,
every JavaScript program is also a TypeScript program
. Hence, a migration from JavaScript to TypeScript code is easily done. - TypeScript compiler emits output even when any errors are reported. In the next section, Advanced types, decorators, and compiler options, we will see how we can forbid emitting JavaScript on errors.
What is the best way to learn the TypeScript language? There is an official handbook on the TypeScript's homepage, which is aligned with the last released version. Hands-on learning is possible with the TypeScript playground (http://www.typescriptlang.org/play), which compiles on-the-fly TypeScript code entered in a browser and shows it side by side with the generated JavaScript code:

Alternatively, you can install the TypeScript globally by typing the following command in the command line:
npm install -g typescript
Global installation means, the TypeScript compiler tsc can be reached and used in any of your projects. Installed Node.js and npm are presupposed. Node.js is the JavaScript runtime environment (https://nodejs.org). npm is the package manager. It is shipped with Node.js, but can be installed separately as well. After that, you can transpile one or more .ts files into .js files by typing the following command:
tsc some.ts another.ts
This will result in two files, some.js and another.js.
- 兩周自制腳本語言
- arc42 by Example
- 實用防銹油配方與制備200例
- Android 7編程入門經典:使用Android Studio 2(第4版)
- SQL語言從入門到精通
- 編譯系統透視:圖解編譯原理
- Python漫游數學王國:高等數學、線性代數、數理統計及運籌學
- Flux Architecture
- Learning FuelPHP for Effective PHP Development
- 程序設計基礎教程:C語言
- HTML5 APP開發從入門到精通(微課精編版)
- OpenGL Data Visualization Cookbook
- Access 2010中文版項目教程
- 小程序從0到1:微信全棧工程師一本通
- Mastering HTML5 Forms