Skip to content

在学习教程HTTP的时候添加英雄,报错!!!!! #49

Open
@xiaochangkun

Description

@xiaochangkun

代码:
add(name: string): void {
name = name.trim();
if (!name) { return; }
this.heroService.addHero({name} as Hero)
.subscribe(hero => {this.heroes.push(hero); });
}

报错:
ERROR in src/app/component/heroes/heroes.component.ts(30,30): error TS2352: Conversion of type '{ name: string; }' to type 'Hero' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'id' is missing in type '{ name: string; }'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    已解决参与者已经有了共识,愿意参与的可继续提问讨论欢迎大家继续参与讨论,征集各方面的观点

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions