let a: object; a = {}; a = []; a = function () { }; /** * 对象: * { * 属性名:类型, * 属性名:类型... * } * ? 可选的 */ let b: { a: number, c: string, d?: string, // 可以添加任意属性任意类型的属性 [propName: string]: any } b = { a: 1, c: 'h', d: "你好", e: "就是", f: 1333 } /** * 函数: * let c:(a:number,b:string)=> string; */ let c: (a: number, b: string) => string; c = function fn1(a: number, b: string) { return a + b; } // console.log(c('12','12')) /** * 数组 * let x:类型[] * let x:Array<类型> */ let d: number[]; d = [1, 2, 3, 4]; let e: Array e = [true, false] // 元祖:固定长度的数组 let f:[number,boolean,string]; f=[1,true,"12"]; // 枚举 enum Sex { man,woman } let g: { name:string, age:number, sex:Sex } g = { name:'图图', age: 3, sex:Sex.man } console.log(g.sex === Sex.woman ? '女' : '男'); // 类型别名 // 或=> | type k = 1|2|3|4; let s1:k = 4; // let s2:k = 41; // 逻辑运算符:& let s3:{name:string}&{age:number}; s3 = { name:"海绵宝宝", age:12 } export { };