【发布时间】:2020-11-07 08:30:20
【问题描述】:
假设我有一个函数,我只想在存在另一个属性时才允许一个属性。
我试图这样做,但它返回错误 Property 'c' does not exist on type 'A'.
type A = {
a?: string;
} & ({ b: string; c?: string } | { b?: string });
const sad = (props: A) => {
const { a, b } = props;
const { c } = props; // Property 'c' does not exist on type 'A'.
return { a, b };
};
有什么解决办法吗?
【问题讨论】:
标签: javascript node.js typescript