相关疑难解决方法(0)

从类型中排除属性

我想从类型中排除一个属性.我怎样才能做到这一点?

比如我有

interface XYZ {
  x: number;
  y: number;
  z: number;
}
Run Code Online (Sandbox Code Playgroud)

我想排除属性z得到

type XY = { x: number, y: number };
Run Code Online (Sandbox Code Playgroud)

typescript

111
推荐指数
7
解决办法
5万
查看次数

将联合类型转换为交集类型

有没有办法将联合类型转换为交集类型:

type FunctionUnion = () => void | (p: string) => void
type FunctionIntersection = () => void & (p: string) => void
Run Code Online (Sandbox Code Playgroud)

我想应用转换FunctionUnion来获取FunctionIntersection

typescript

55
推荐指数
4
解决办法
4645
查看次数

标签 统计

typescript ×2