CaptainOfPhB
TypeScript 学习笔记(一)

· 325 words · 2 min

let x: [string, number];
x = ['hello', 123]; // ok
x = [123, 'hello']; // error
// 越界元素将是 (number | string) 类型
x[3] = 'world';
let someValue: any = 'this is a string'
let strLength: number = (someValue as string).length

完。

TypeScript