import type { FieldsValue, Struct, StructFields } from "./struct.js"; import { struct } from "./struct.js"; type UnionToIntersection = ( U extends unknown ? (x: U) => void : never ) extends (x: infer I) => void ? I : never; type As = T extends infer V extends U ? V : never; export type ConcatFields< T extends Struct< StructFields, Record | undefined, unknown >[], > = As, StructFields>; type ConcatFieldValues< T extends Struct< StructFields, Record | undefined, unknown >[], > = FieldsValue>; type ExtraToUnion | undefined> = Extra extends undefined ? never : Extra; export type ConcatExtras< T extends Struct< StructFields, Record | undefined, unknown >[], > = As< UnionToIntersection>, Record >; /* #__NO_SIDE_EFFECTS__ */ export function concat< T extends Struct< StructFields, Record | undefined, unknown >[], PostDeserialize = ConcatFieldValues & ConcatExtras, >( options: { littleEndian: boolean; postDeserialize?: ( this: ConcatFieldValues & ConcatExtras, value: ConcatFieldValues & ConcatExtras, ) => PostDeserialize; }, ...structs: T ): Struct, ConcatExtras, PostDeserialize> { return struct( structs.reduce( (fields, struct) => Object.assign(fields, struct.fields), {}, ) as never, { littleEndian: options.littleEndian, postDeserialize: options.postDeserialize, extra: structs.reduce( (extras, struct) => Object.defineProperties( extras, Object.getOwnPropertyDescriptors(struct.extra), ), {}, ) as never, }, ) as never; }