//string
let studentName: String = "xiaoming";

//number
let studentAge: number = 18;

//Boolean
let isChecked: Boolean = true;

//Date
let now: Date = new Date();

//定义接口
interface StudentInt {
  name: string;
  age: number;
  isChecked?: boolean;
  works?: Array<string>;
}

//定义函数接口
interface CheckCountFunction {
  (studentList: Array<StudentInt>): number;
}

//Array
let studentList1: Array<{ name: string; age: number; isChecked?: boolean }> = [
  { name: "xiaoming", age: 18 },
  { name: "xiaowang'", age: 18, isChecked: true },
];

let studentnew: StudentInt = {
  name: "xiaoming",
  age: 18,
  isChecked: false,
  works: ["yuwen"],
};
studentList1.push(studentnew);

/**接口：实现提示词检索
 * @param progress {number} 任务进度
 * @param complete {boolean} 任务是否完成
 * @param errorMsg {string} 错误信息
 */
interface AgentTask {
  progress: number; //任务进度
  complete: boolean; //任务是否完成
  errorMsg: string; //错误信息
}

let task1: AgentTask = { progress: 1, complete: true, errorMsg: "youwenti" };

/**
 * 统计人数 没有接口表示
 * @param studentList{Array<StudentInt}  学生列表
 * @returns
 */
function checkCount1(studentList: Array<StudentInt>): number {
  // let checkList = studentList.map(item=>item.isChecked ? 1:0)
  // let count = 0;
  // checkList.forEach(check=>{
  //   if(check==1)
  //     count ++
  // })
  let checkList = studentList.map((item): 1 | 0 => (item.isChecked ? 1 : 0));
  let count = 0;
  checkList.forEach((checked) => {
    if (checked == 1) count++;
  });
  return count;
}
/**
 * 统计人数 用函数接口表示
 * @param studentList{Array<StudentInt}  学生列表
 * @returns
 */
const checkCount: CheckCountFunction = (
  studentList: Array<StudentInt>
): number => {
  let checkList = studentList.map((item): 1 | 0 => (item.isChecked ? 1 : 0));
  let count = 0;
  checkList.forEach((checked) => {
    if (checked === 1) count++;
  });
  return count;
};
let count = checkCount(studentList1);
console.log(count);
