小编seg*_*egu的帖子

我如何在打字稿上制作多类型属性接口

我想在打字稿中使用两个不同的接口创建接口属性。这可能吗?

interface IPayload1 {
  id: string;
  name: string;
}
interface IPayload2 {
  id: string;
  price: number;
}

interface Demo {
  // Can this be possible?
  payload: IPayload1 | IPayload2;
}
Run Code Online (Sandbox Code Playgroud)

interface typescript typescript-typings

3
推荐指数
1
解决办法
4056
查看次数

标签 统计

interface ×1

typescript ×1

typescript-typings ×1