gpt4 book ai didi

angular - 源具有X个元素,但目标仅允许1个

转载 作者:行者123 更新时间:2023-12-03 15:41:51 32 4
gpt4 key购买 nike

typescript 编译显示此错误:

Source has X element(s) but target allows only 1.

export const FooMapping: [{id: FooOperation, display: string}] = [
{ id: FooOperation.Undefined, display: 'Nothing' },
{ id: FooOperation.A, display: 'I'm A' },
{ id: FooOperation.B, display: 'I'm B' }
];

export enum FooOperation {
Undefined = 0,
A = 1,
B = 2,
}
定义 {id: FooOperation, display: string}特殊对象数组的正确方法是什么?

最佳答案

[{id: FooOperation, display: string}]定义了一个只包含一个元素的tuple
尝试:

export const FooMapping: Array<{id: FooOperation; display: string}> = [
{ id: FooOperation.Undefined, display: 'Nothing' },
{ id: FooOperation.A, display: "I'm A" },
{ id: FooOperation.B, display: "I'm B" }
];
或考虑类似以下内容的事情:
interface Foo {
id: FooOperation;
display: string;
}

export const FooMapping: Foo[] = [...];

关于angular - 源具有X个元素,但目标仅允许1个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64308563/

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