相关疑难解决方法(0)

打字稿2.8:从另一种类型中删除一种类型的属性

在2.8的变更日志中,它们具有条件类型的以下示例:

type Diff<T, U> = T extends U ? never : T;  // Remove types from T that are assignable to U
type T30 = Diff<"a" | "b" | "c" | "d", "a" | "c" | "f">;  // "b" | "d"
Run Code Online (Sandbox Code Playgroud)

除了删除对象的属性外,我想这样做。如何实现以下目标:

type ObjectDiff<T, U> = /* ...pls help... */;

type A = { one: string; two: number; three: Date; };
type Stuff = { three: Date; };

type AWithoutStuff = ObjectDiff<A, Stuff>; // { one: …
Run Code Online (Sandbox Code Playgroud)

typescript conditional-types typescript2.8

5
推荐指数
1
解决办法
637
查看次数