gpt4 book ai didi

javascript - 错误 : Type String is not assignable to type '{ name : string; }' in Angular

转载 作者:行者123 更新时间:2023-11-30 15:18:40 28 4
gpt4 key购买 nike

我正在尝试在 Angular 2 中定义一个范围变量。这是代码:

export class GroceryComponent {
task = {
name: ''
};
tasks = [];
}

但它抛出以下错误:

Type String is not assignable to type '{ name : string; }' 

最佳答案

可能您代码的其他部分试图更改 task来自 instance 的属性(property)的 GroceryComponent


与此错误类似的内容:

class GroceryComponent {
task = {
name : ""
};
tasks = [];
};

let product = new GroceryComponent();
product.task = 55; // ERROR MESSAGE: Type '55' is not assignable to type '{ name: string; }'.

交互式示例:TypeScript Playground

关于javascript - 错误 : Type String is not assignable to type '{ name : string; }' in Angular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44111724/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com