fix: modify type checking for min/max defaults

This commit is contained in:
Convly 2024-02-13 09:52:25 +01:00
parent aa7c7ec672
commit 82b9d6e4b1

View File

@ -114,21 +114,21 @@ const getAttributeModifiers = (attribute) => {
throw new Error('typeof min/max values mismatch'); throw new Error('typeof min/max values mismatch');
} }
const typeofMinMax = (max && typeofMax) ?? (min && typeofMin);
let typeKeyword; let typeKeyword;
// Determines type keyword (string/number) based on min/max options, throws error for invalid types // use 'string'
switch (typeofMinMax) { if (typeofMin === 'string' || typeofMax === 'string') {
case 'string': typeKeyword = ts.SyntaxKind.StringKeyword;
typeKeyword = ts.SyntaxKind.StringKeyword; }
break; // use 'number'
case 'number': else if (typeofMin === 'number' || typeofMax === 'number') {
typeKeyword = ts.SyntaxKind.NumberKeyword; typeKeyword = ts.SyntaxKind.NumberKeyword;
break; }
default: // invalid type
throw new Error( else {
`Invalid data type for min/max options. Must be string or number, but found ${typeofMinMax}` 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( modifiers.push(