Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/__tests__/unions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ test('Long module is imported when needed', () => {
import thrift2flow$Long from \\"long\\";

export type RawValue =
| {| binaryValue: Buffer |}
| {| boolValue: boolean |}
| {| doubleValue: number |}
| {| int32Value: number |}
| {| int64Value: number | thrift2flow$Long |}
| {| stringValue: string |};
| {| type: \\"binaryValue\\", binaryValue: Buffer |}
| {| type: \\"boolValue\\", boolValue: boolean |}
| {| type: \\"doubleValue\\", doubleValue: number |}
| {| type: \\"int32Value\\", int32Value: number |}
| {| type: \\"int64Value\\", int64Value: number | thrift2flow$Long |}
| {| type: \\"stringValue\\", stringValue: string |};
"
`);
});
Expand Down Expand Up @@ -82,6 +82,13 @@ function go(s : MyStruct, u: UnionTypedef, eu: EmptyUnionTypedef) {
const emptyunionDefs: EmptyUnionTypedef[] = [s.f_EmptyUnionTypedef];
const strings: string[] = [s.f_MyUnion.name || ''];
const numbers: number[] = [s.f_MyUnion.size || -1];
const myUnion = s.f_MyUnion;
// testing out type refinement using the type key
if (myUnion.type === 'name') {
(myUnion.name: string)
} else {
(myUnion.size: number)
}
return [unions,unions,unionDefs,emptyunionDefs,strings,numbers];
}
`,
Expand Down
5 changes: 4 additions & 1 deletion src/main/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ export class ThriftFileConverter {
return '{||}';
}
return fields
.map((f: Field) => `{|${f.name}: ${this.convertType(f.valueType)}|}`)
.map(
(f: Field) =>
`{|type: "${f.name}",${f.name}: ${this.convertType(f.valueType)}|}`
)
.join(' | ');
};

Expand Down