TypeScript 入门
首先,我们创建一个 index.html 文件:
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Learning TypeScript</title>
- </head>
- <body>
- <script src="hello.js"></script>
- </body>
- </html>
创建 hello.ts 文件, *.ts 是 TypeScript 文件的后缀,向 hello.ts 文件添加如下代码:
- alert('hello world in TypeScript!');
接下来,我们打开命令行,使用 tsc 命令编译 hello.ts 文件:
- $ tsc hello.ts
在相同目录下就会生成一个 hello.js 文件,然后打开 index.html 输出结果如下:

转载本站内容时,请务必注明来自W3xue,违者必究。