File tree 1 file changed +5
-5
lines changed
1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 1
1
# 入门
2
2
3
- TS入门是比较简单的,后面学习曲线会越来越陡峭,无论类型推导,还是面向对象,都是需要投入非常大经历学习的 。
3
+ TS入门是比较简单的,后面学习曲线会越来越陡峭,无论类型推导,还是面向对象,都是需要投入非常大精力学习的 。
4
4
5
5
本节主要讲解ts入门必须要掌握的4个点。
6
6
@@ -52,7 +52,7 @@ JavaScript有一个庞大的开发者社区,而TypeScript没有。
52
52
- ` typeof ` 关键字用于判断是否是某种类型
53
53
- ` string ` 表明是字符串类型,它不同于Java,首字母是小写
54
54
- ` boolean ` 和 ` Boolean ` 类型是不同的
55
- - ` number ` 直接表示数字类型,没有那么多麻烦的精度问题(0b、0O、0x指明进度问题 )
55
+ - ` number ` 直接表示数字类型,没有那么多麻烦的精度问题(0b、0O、0x指明进制问题 )
56
56
- [ ` any ` ] ( https://www.zhihu.com/search?q=any&search_source=Entity&hybrid_search_source=Entity&hybrid_search_extra=%7B%22sourceType%22%3A%22answer%22%2C%22sourceId%22%3A3126865898%7D ) 是万能类型,相当于Java中的Object,全部是any相当于是普通js。所以,如果你恨ts,就可以一路any到天明
57
57
- ` never ` 表示那些永不存在的值类型
58
58
- ` object ` 表示非原始类型,和Java中的不太一样
@@ -89,7 +89,7 @@ document.write(jsCode);
89
89
90
90
有了这个环境分离基础,那么就可以实现在浏览器端运行 ts compiler!因为 ts compiler 本身编译后也是 js,只需要提供一个浏览器端的 compilerHost 就可以,typescript 官方提供了一个虚拟文件服务包@typescript/vfs 提供浏览器端兼容的 fs 服务
91
91
92
- ``` tsx
92
+ ``` jsx
93
93
import ts from ' typescript'
94
94
import tsvfs from ' @typescript/vfs' // 虚拟文件服务
95
95
import lzstring from ' lz-string' // 一个压缩算法
@@ -124,14 +124,14 @@ const program = ts.createProgram({
124
124
125
125
通过编译器编译
126
126
127
- ``` tsx
127
+ ``` bash
128
128
$ npm install -g typescript
129
129
$ tsc hello.ts
130
130
```
131
131
132
132
通过代码
133
133
134
- ``` tsx
134
+ ``` jsx
135
135
const { outputText } = ts .transpileModule (your_ts_code, {
136
136
compilerOptions: {
137
137
strict: false ,
You can’t perform that action at this time.
0 commit comments