联合类型不适用于对象文字

时间:2018-01-12 17:07:49

标签: flowtype

请参阅下面的flowtry。第17行是联合类型和对象文字之间的联合。当我在第36行使用类型时,它告诉我它找不到联合中类型的属性。

有谁知道我在这里做错了什么?

type NativeMockPlayerSourceConfig = {}

type BitmovinPlayerSourceConfig =
  | BitmovinPlayerSourceConfigHLS
  | BitmovinPlayerSourceConfigDash

type BitmovinPlayerSourceConfigHLS = {
  tag: 'HLS',
  hls: string,
}

type BitmovinPlayerSourceConfigDash = {
  tag: 'DASH',
  dash: string,
}

type LiveSourceConfig = BitmovinPlayerSourceConfig | NativeMockPlayerSourceConfig

interface NativePlayer {
  +load: LiveSourceConfig => Promise<void>,
}

type NativeBitmovinPlayer = {
  load: BitmovinPlayerSourceConfig => Promise<NativeBitmovinPlayer>,
}

type PromisePassthrough<C: any> = any => Promise<C>

type NativeMockPlayer = {
  load: PromisePassthrough<NativeMockPlayer>,
}

class BitmovinPlayer implements NativePlayer {
  ref: NativeBitmovinPlayer

  async load(source: BitmovinPlayerSourceConfig) {
    await this.ref.load(source)
  }
}

class MockPlayer implements NativePlayer {
  ref: NativeMockPlayer

  async load(config: NativeMockPlayerSourceConfig) {
    this.ref.load(config)
  }
}

谢谢

flowtry

1 个答案:

答案 0 :(得分:1)

我不确定这是最好的方法,但这有效:

flowtry