- Expert Angular
- Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
- 282字
- 2021-07-15 17:05:29
Basics of TypeScript
TypeScript is a superset of JavaScript and is an open source language developed by Microsoft. Code written in TypeScript will be compiled to JavaScript and executed on any browser or server running Node.js. TypeScript is actually a type of JavaScript. TypeScript helps to improve the quality of code you write in JavaScript. If we use external libraries, we need to use type definition files for the imported libraries. Type definition files provide JavaScript tooling support and also enable compile time checks, code refactoring, and variable renaming support by inferring the structure of the code. TypeScript is evolving and keeps adding additional features aligned with the ES2016 specification and later.
There are various editors available on the market that write TypeScript code and compile them using a TypeScript compiler. These editors take care of compiling your TypeScript into JavaScript. Some popular editors are shown here:
- Visual Studio
- Visual Studio Code
- Sublime text
- Atom
- Eclipse
- Emacs
- WebStorm
- Vim
You can also download TypeScript as a Node.js package by executing the following command in the Node.js command-line tool to install TypeScript globally:
npm install -g typescript
To transpile the TypeScript code into JavaScript, you can execute the following command in the command-line tool:
tsc mytypescriptcodefile.ts
Here, tsc is the TypeScript compiler that converts a TypeScript file into a JavaScript file. mytypescriptfile is the name of your TypeScript code file and .ts is the extension of the TypeScript file. On executing the tsc command, it generates a .js file with the same name as the .ts source file.
We will be using Visual Studio Code editor for our sample code demos in this chapter. Let us see basic features of TypeScript with examples.
- 嵌入式軟件系統(tǒng)測(cè)試:基于形式化方法的自動(dòng)化測(cè)試解決方案
- 工程軟件開(kāi)發(fā)技術(shù)基礎(chǔ)
- Python從小白到大牛
- C# 從入門(mén)到項(xiàng)目實(shí)踐(超值版)
- Learning Bayesian Models with R
- OpenStack Cloud Computing Cookbook(Fourth Edition)
- Neo4j Essentials
- DevOps Automation Cookbook
- 精通API架構(gòu):設(shè)計(jì)、運(yùn)維與演進(jìn)
- 假如C語(yǔ)言是我發(fā)明的:講給孩子聽(tīng)的大師編程課
- Apache Kafka Quick Start Guide
- 用案例學(xué)Java Web整合開(kāi)發(fā)
- Unity 3D/2D移動(dòng)開(kāi)發(fā)實(shí)戰(zhàn)教程
- App Inventor創(chuàng)意趣味編程進(jìn)階
- ExtJS Web應(yīng)用程序開(kāi)發(fā)指南第2版