# TypeScript

因为JavaScript的动态类型不适合用于大型项目的维护，所以微软公司开发了以JavaScript为基础构建的TypeScript语言，是一个JavaScript超集。就像他的名字一样，ts相比较与js，扩展了js并增加了类型，并且由弱类型语言转换为了**强类型语言**。ts可以被任何支持js的平台执行，但是不可以被js解析器直接执行，需要通过编译，将ts转换为js（就像less一样）。

ts对js的扩展：

* 强类型
* 支持ES新特性
* 丰富的配置项
* 将ts编译为任意版本的es，解决了浏览器问题

## 构建TypeScript环境

保证首先要有`Node.js`环境，并在命令台使用npm命令安装TypeScript：

```console
npm install -g typescript
```

## Hello World

```shell
$ echo 'console.log("hello world")' > helloworld.ts
$ tsc helloworld.ts
$ ll
total 16
-rw-r--r--  1 yangsx  staff    28B  9 20 12:22 helloworld.js # 编译为了js
-rw-r--r--  1 yangsx  staff    27B  9 20 12:21 helloworld.ts
# 执行js脚本
$ node helloworld.js
hello world
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yangsx95.gitbook.io/notes/programming-language/typescript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
