TypeScript

11/9/2022 前端ts
(adsbygoogle = window.adsbygoogle || []).push({});

# 简介

  1. 微软开发的,是js的超集
  2. 编译时类型检查
  3. 最终编译成js
  4. 扩展名ts,由tsc编译为js
  5. 区分大小写

# 数据类型

# 基本

任意 Any 元组 枚举enum

# 联合类型

||||

# 声明

var [变量名]: [类型] = 值

# 断言

as

函数指定返回值类型

# 接口

ts特有的,不能转为js ?表示可选参数

declare namespace API {
    interface IUser {
        id: number,
        userId: string,
        userName: string,
        password: string,
        status: string,
        createId: string,
        createTims: Date,
        modifyId: string,
        modifyTime: Date
    }
    interface TableParams {
        pagination?: TablePaginationConfig;
        sortField?: string;
        sortOrder?: string;
        filters?: Record<string, FilterValue>;
    }
    interface PageInfo {
        total?: number,
        pageSize?: number,
        pageNum?: number,
        list?: any[]
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# 命名空间

和声明文件.d.ts联用

# 注意

ts中一些注释会影响报错,例如: 忽略ts检查

// @ts-ignore 
1

https://www.runoob.com/w3cnote/getting-started-with-typescript.html