TypeScript 基础类型详解

TypeScript 的基础类型

TypeScript 提供了丰富的类型系统:布尔、数字、字符串、数组、元组、枚举等。

let isDone: boolean = false;
let decimal: number = 6;
let color: string = "blue";
let list: number[] = [1, 2, 3];
let tuple: [string, number] = ["hello", 42];
enum Direction { Up, Down, Left, Right }

还有 anyunknownnever 等特殊类型,以及类型断言 as 语法。

comments powered by Disqus