我有这个代码stackblitzexport class Student { id: number; name: string; age?:number; get studentType():string { return 'fullTime' } constructor(params: Student) { Object.assign(this, params); }}const student = new Student({id:1, name: 'Jon'}); //ts error here我收到以下错误'{ id: number; 类型的参数 名称:字符串;}' 不能分配给'Student' 类型的参数。类型“{ id: number;”中缺少属性“studentType” 名称:字符串;}'。而 studentType 是一个只能获取的属性,不能下注。这是什么原因,我该如何解决?附:(我不想让它像可空一样studentType?或将它转换为一个函数)
添加回答
举报
0/150
提交
取消