![](/img/trans.png)
[英]Typescript ts2322: Type '{ id: number, name: string, paymentStatus: string }' is not assignable to type
[英]TS 2322 - Property 'id' is missing in type '{ id: number
Angular和TS新手。 我创建了具有相同属性的模型,但我得到错误,无法找到解决方案:
TS2322:输入'{id:number; model:string; 盘子 deliveryDate:string; 截止日期:字符串; client:{fir ...'不能分配给'Car'类型。 类型'{id:number; model:string; 盘子 deliveryDate:string; 截止日期:字符串; 客户:{fir ...'。 汽车:汽车= [
我的文件:
//cars-list.component.ts
import { Car } from '../models/car';
.
.
.
cars : Car = [
{
id: 1,
model: 'Mazda Rx7',
plate: 'GD2121E',
deliveryDate: '21-04-2017',
deadline: '05-05-2016',
client: {
firstName: 'Jan',
surname: 'Kowalski'
},
cost: 300,
isFullyDamaged: true
},
...
和
//car.ts
import {Client} from './client';
export interface Car {
id: number;
model: string;
plate: string;
deliveryDate: string;
deadline: string;
client: Client;
cost: number;
isFullyDamaged: boolean;
}
您正在尝试将对象数组分配给Car类型的变量。 使变量成为汽车数组。
cars : Car[] = [
对于那些和我一样的人:
var myObject = objects.filter(o => o.id === id)
用find()替换它以返回一个对象而不是一个数组:
var myObject = objects.find(o => o.id === id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.