// 布尔数组
a: boolean = true函数
// 数字oop
a: number = 1this
// 字符串spa
a: string = '1'code
// 数组字符串
a: number[] = [1,2,3]string
// 元组 tuple (已知数量与类型)it
a: [string, number]io
// 枚举
enum a: {red, black, green}
// 任意值
a: any = 1
// 空值
function test(): void{}
// 永不存在的值
// 返回never的函数必须存在没法达到的终点 function error(message: string): never { throw new Error(message); } // 推断的返回值类型为never function fail() { return error("Something failed"); } // 返回never的函数必须存在没法达到的终点 function infiniteLoop(): never { while (true) { } }
as 语法,明确知道哪种类型
a: any = 'this is a string'
b: number = (a as string).length