From a83ae847af4d6b937a03f71c4b3d35cffcac348b Mon Sep 17 00:00:00 2001 From: Skye <63878374+MierenManz@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:12:06 +0100 Subject: [PATCH 1/2] Update src/compound/tagged_union.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elias Sjögreen --- src/compound/tagged_union.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compound/tagged_union.ts b/src/compound/tagged_union.ts index e5ff57f..fbb2429 100644 --- a/src/compound/tagged_union.ts +++ b/src/compound/tagged_union.ts @@ -31,7 +31,7 @@ export class TaggedUnion< readUnaligned(dt: DataView, options: Options = { byteOffset: 0 }): V { const discriminant = this.#discriminant.readUnaligned(dt, options); const codec = this.#record[discriminant]; - if (!codec) throw new Error("Unknown discriminant"); + if (!codec) throw new TypeError("Unknown discriminant"); super.alignOffset(options); return codec.read(dt, options) as V; From d0285522020e37e23322e8a7e7e905bba200c265 Mon Sep 17 00:00:00 2001 From: Skye <63878374+MierenManz@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:12:32 +0100 Subject: [PATCH 2/2] Update src/compound/tagged_union.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elias Sjögreen --- src/compound/tagged_union.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compound/tagged_union.ts b/src/compound/tagged_union.ts index fbb2429..0db6ee6 100644 --- a/src/compound/tagged_union.ts +++ b/src/compound/tagged_union.ts @@ -19,7 +19,7 @@ export class TaggedUnion< #variantFinder: Fn; #discriminant = u8; - constructor(input: T, variantFinder: Fn) { + constructor(input: T, discriminator: Type<...> = u8) { // Find biggest alignment const byteAlignment = Object.values(input) .reduce((acc, x) => Math.max(acc, x.byteAlignment), 0);