From 82b9d6e4b19059846088aab3ad7b3d1af65f77b8 Mon Sep 17 00:00:00 2001 From: Convly Date: Tue, 13 Feb 2024 09:52:25 +0100 Subject: [PATCH] fix: modify type checking for min/max defaults --- .../generators/common/models/attributes.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/utils/typescript/lib/generators/common/models/attributes.js b/packages/utils/typescript/lib/generators/common/models/attributes.js index a39f9419f4..b3e7dbd646 100644 --- a/packages/utils/typescript/lib/generators/common/models/attributes.js +++ b/packages/utils/typescript/lib/generators/common/models/attributes.js @@ -114,21 +114,21 @@ const getAttributeModifiers = (attribute) => { throw new Error('typeof min/max values mismatch'); } - const typeofMinMax = (max && typeofMax) ?? (min && typeofMin); let typeKeyword; - // Determines type keyword (string/number) based on min/max options, throws error for invalid types - switch (typeofMinMax) { - case 'string': - typeKeyword = ts.SyntaxKind.StringKeyword; - break; - case 'number': - typeKeyword = ts.SyntaxKind.NumberKeyword; - break; - default: - throw new Error( - `Invalid data type for min/max options. Must be string or number, but found ${typeofMinMax}` - ); + // use 'string' + if (typeofMin === 'string' || typeofMax === 'string') { + typeKeyword = ts.SyntaxKind.StringKeyword; + } + // use 'number' + else if (typeofMin === 'number' || typeofMax === 'number') { + typeKeyword = ts.SyntaxKind.NumberKeyword; + } + // invalid type + else { + throw new Error( + `Invalid data type for min/max options. Must be string, number or undefined, but found { min: ${min} (${typeofMin}), max: ${max} (${typeofMax}) }` + ); } modifiers.push(