SOURCE

function showPersonInfo(obj: {
  name: string;
  age: number
}: object) : string {

  return obj.name + '--' + obj.age;
}
console.log(showPersonInfo({
  name: 'xxxx',
  age: 22
});

let msg = function(x: string, y ? :string) {
  // console.log(x + y);
  if (y) {
    console.log(x + y);
  } else {
    console.log(x);
  }
}; msg('lalalal', 'ddddd'); msg('ddddd');

function arr(arr: number[]) {
  arr.forEach(function(v, i) {
    console.log(v, i);
  });
}
arr([1, 2, 3, 2, 4]);

interface LabelledValue {
  label: string;
}

function printLabel(labelledObj: LabelledValue) {
  console.log(labelledObj.label);
}

let myObj = {
  size: 10,
  label: "Size 10 Object"
}; printLabel(myObj);
//函数返回值类型定义
function cssStyle(obj: {
  width: string,
  height: string
}) : {
  width: string,
  height: string,
  'border-radius': string
} {
  return {
    width: obj.width,
    height: obj.height,
    'border-radius': obj.width
  };
}
console.log(cssStyle('100px', '200px'));
console 命令行工具 X clear

                    
>
console