相关疑难解决方法(0)

如何创建类似于Partial的,需要设置单个属性

我们的结构如下:

export type LinkRestSource = {
    model: string;
    rel?: string;
    title?: string;
} | {
    model?: string;
    rel: string;
    title?: string;
} | {
    model?: string;
    rel?: string;
    title: string;
};
Run Code Online (Sandbox Code Playgroud)

这几乎与说法相同

type LinkRestSource = Partial<{model: string, rel: string, title: string}>
Run Code Online (Sandbox Code Playgroud)

除了这将允许传入空对象,而初始类型需要传递其中一个属性

我怎样才能创建类似的泛型Partial,但其行为与上面的结构相似?

generics typescript

16
推荐指数
4
解决办法
4051
查看次数

标签 统计

generics ×1

typescript ×1