官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 阿巴嘎旗| 杭州市| 苏尼特左旗| 家居| 南陵县| 连城县| 大庆市| 无锡市| 安平县| 汽车| 宁波市| 彩票| 甘孜县| 乌兰察布市| 高平市| 左云县| 旅游| 新兴县| 滕州市| 玉田县| 上林县| 清涧县| 淄博市| 伽师县| 长沙县| 平湖市| 桂阳县| 滦南县| 滦南县| 临颍县| 洪雅县| 屏东县| 昆山市| 成都市| 满洲里市| 神农架林区| 图们市| 达州市| 昭苏县| 班玛县| 阜新|