export class OtherExample { execute() { /** ---------------------- typescript 2.6 ----------------------- */ //通过 '// @ts-ignore' 注释隐藏 .ts 文件中的错误 if (false) { // @ts-ignore console.log(1); } let a: number; //@ts-ignore // a.a = 1; // /** ---------------------- typescript 2.7 -------------------- */ // let x!: number[]; // initialize(); // x.push(4); // function initialize() { // x = [0, 1, 2, 3]; // } /** ---------------------- typescript 2.0 -------------------- */ //非空断言操作符 TODO // let object = { a: 1, b: 2 }; // object = null; // if (object!.a) { // console.log('*****************'); // } else { // console.log('##################'); // } /** ----------------------对象扩展运算符与rest运算符------------------------------- */ let obj = { x: 1, y: 100 }; let newObject = { ...obj, width: 100, height: 100 }; //rest 前面的必须从最后的数据填起,...对象为剩余的 let { width, height, ...obj1 } = newObject; //--------------------- typescript 2.5 ----------------------// //可选的 catch语句变量 let input = "..."; try { JSON.parse(input); } catch { // ^ 注意我们的 `catch` 语句并没有声明一个变量 console.log("传入的 JSON 不合法\n\n" + input); } //---------------------------ES7 幂运算符--------------------------// let value = 2 ** 3; } }