Derek Bailey 82b75407a3
Wrap types in namespace for --ts-flat-files and --gen-all (#7451)
* Wrap types in namespace for --ts-flat-files and --gen-all

* Fixes for escaping object types

* Added to generate_code
2022-08-16 12:52:26 -07:00

37 lines
1.0 KiB
TypeScript

// automatically generated by the FlatBuffers compiler, do not modify
import { FallingTub, FallingTubT } from './falling-tub';
import { HandFan, HandFanT } from './hand-fan';
export enum Gadget {
NONE = 0,
FallingTub = 1,
HandFan = 2
}
export function unionToGadget(
type: Gadget,
accessor: (obj:FallingTub|HandFan) => FallingTub|HandFan|null
): FallingTub|HandFan|null {
switch(Gadget[type]) {
case 'NONE': return null;
case 'FallingTub': return accessor(new FallingTub())! as FallingTub;
case 'HandFan': return accessor(new HandFan())! as HandFan;
default: return null;
}
}
export function unionListToGadget(
type: Gadget,
accessor: (index: number, obj:FallingTub|HandFan) => FallingTub|HandFan|null,
index: number
): FallingTub|HandFan|null {
switch(Gadget[type]) {
case 'NONE': return null;
case 'FallingTub': return accessor(index, new FallingTub())! as FallingTub;
case 'HandFan': return accessor(index, new HandFan())! as HandFan;
default: return null;
}
}