web前端全系列 教程
1839个小节阅读:2243.5k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
我们所编写的应用程序最终是需要运行在浏览器中的,但是浏览器能识别的语言是JavaScript而非TypeScript。那么问题来了,我们编写TypeScript的代码如何运行在浏览器中呢?答案:将TypeScript编译成JavaScript代码在运行在浏览器中!
xxxxxxxxxx
npm install -g typescript
以上命令会在全局环境下安装 tsc
命令,安装完成之后,我们就可以在任何地方执行 tsc
命令了
检查是否安装成功:tsc -v
xxxxxxxxxx
// hello.ts
function add(n:number,m:number){
console.log(n+m)
}
add(10,20);
编译一个 TypeScript 文件很简单
xxxxxxxxxx
tsc hello.ts
xfunction sayHello(person: string) {
return "Hello, " + person;
}
let user = "itbaizhan";
document.body.textContent = sayHello(user);
xxxxxxxxxx
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="./hello.js"></script>
</body>
</html>
实时效果反馈
1. 编译一个TypeScript文件hello.ts
的命令是:
A tsc -v
B ts hello.ts
C tsc hello.ts
D tsc hello.js
答案
1=>C