在下面的例子中,有人知道如何编写field
变量,使其符合给定的接口(因此我们不应该改变接口)吗?现在我得到一个错误,说Type '{ accountId: string; active: true; }[]' is not assignable to type 'never'.
interface Fields {
votes: Votes & {
voters: never;
};
}
interface Votes {
self: string;
votes: number;
hasVoted: boolean;
voters: User[];
}
interface User {
accountId: string;
active: boolean;
}
const field: Fields = {
votes: {
self: "self",
votes: 0,
hasVoted: false,
voters: [
{
accountId: "accountId",
active: true,
},
],
},
};
字符串
1条答案
按热度按时间t3psigkw1#
never
不能赋值任何东西,所以你必须使用类型Assert来强制它。例如:字符串
Playground链接