zliz
zliz

Reputation: 59

Union type doesn't work with object literal

Please see flowtry below. Line 17 is a union between a union type and an object literal. When I use the type on line 36, it tells me it can't find the properties of the type within the union.

Does anyone know what I'm doing wrong here?

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)
  }
}

Thank you

flowtry

Upvotes: 1

Views: 47

Answers (1)

timofeyka
timofeyka

Reputation: 300

I'm not sure this is the best way but this works:

flowtry

Upvotes: 1

Related Questions