From eb63957b08d16ddb2209d08407d464e27beda670 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 30 Sep 2020 14:20:42 +0200 Subject: [PATCH] Pull out IntegerStatic --- packages/math/src/integers.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/math/src/integers.ts b/packages/math/src/integers.ts index e57d1468..573efefa 100644 --- a/packages/math/src/integers.ts +++ b/packages/math/src/integers.ts @@ -14,9 +14,12 @@ interface WithByteConverters { readonly toBytesLittleEndian: () => Uint8Array; } +interface IntegerStatic { + readonly fromString: (str: string) => T; +} + interface FixedLengthIntegerStatic { readonly fromBytes: (bytes: ArrayLike, endianess: "be" | "le") => T; - readonly fromString: (str: string) => T; } export class Uint32 implements Integer, WithByteConverters { @@ -105,8 +108,6 @@ export class Uint32 implements Integer, WithByteConverters { } } -const _uint32ClassConformsToStaticInterface: FixedLengthIntegerStatic = Uint32; - export class Int53 implements Integer { public static fromString(str: string): Int53 { if (!str.match(/^-?[0-9]+$/)) { @@ -249,4 +250,9 @@ export class Uint64 implements Integer, WithByteConverters { } } -const _uint64ClassConformsToStaticInterface: FixedLengthIntegerStatic = Uint64; +// Assign classes to unused variables in order to verify static interface conformance at compile time. +// Workaround for https://github.com/microsoft/TypeScript/issues/33892 +const _int53Class: IntegerStatic = Int53; +const _uint53Class: IntegerStatic = Uint53; +const _uint32Class: IntegerStatic & FixedLengthIntegerStatic = Uint32; +const _uint64Class: IntegerStatic & FixedLengthIntegerStatic = Uint64;