typescript 笔记

121 阅读1分钟

地址:www.typescriptlang.org/docs/handbo…

Array

声明数组两种方式 let list: number[] = [1, 2, 3]; 或者 let list: Array = [1, 2, 3];

Tuple(元组)

就是生命数组里边可以不同类型

// Declare a tuple type
let x: [string, number];
// Initialize it
x = ["hello", 10]; // OK
// Initialize it incorrectly
x = [10, "hello"]; // Error

Type assertions

声明是数据是某种类型

Readonly properties

只读的 设定之后,就不可以改变

interface Point {
    readonly x: number;
    readonly y: number;
}