【问题标题】:Equivalent of Type Spread from Flow in Typescript?相当于打字稿中流的类型传播?
【发布时间】:2019-01-24 08:06:29
【问题描述】:

在 Flow 中我们可以这样做:

type Props<T> = {
  ...T,
  other: string,
}

在打字稿中是否有等价物?我正在尝试将我的代码转换为打字稿,但是像这样的一些基本内容令人非常头疼。在任何地方都找不到与此相关的任何内容。

【问题讨论】:

  • 你的意思是,除了intersections?
  • 如果你真的需要传播而不是交集(也就是说,你想覆盖来自T的任何碰撞属性)你必须build it yourself映射和条件类型。
  • 谢谢。就是这样!

标签: typescript flowtype


【解决方案1】:

这不是您所要求的,但也许您只是想扩展?

interface A {
  foo: string;
}
interface B extends A {
  bar: number;
}

const x: B = {
  foo: "some",
  bar: 10
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 2018-12-13
    • 2022-12-03
    • 1970-01-01
    • 2019-09-28
    • 2021-08-22
    • 2022-11-13
    相关资源
    最近更新 更多