creditkarma / thrift-typescript

Generate TypeScript from Thrift IDL files
Apache License 2.0
155 stars 32 forks source link

fix type issue with map constants that reference other maps or sets #182

Open hayes opened 4 years ago

hayes commented 4 years ago

The initializer arrays for generated map constants don't always type check correctly.

Basically the issue happens when the inferred type of 2 map entries are different

const map: Map<string, Set<Enum> = new Map<[
  ['abc', new Set([Enum.One], // [string, Set<1>]
  ['abc', new Set([Enum.Two],  // [string, Set<2>]
  ]) // error with something like (['abc', new Set([Enum.Two] || [string, Set<2>])[] is not assignable to [string, Set<Set<Enum>][]

Adding explicit type to the map fixes this.