Skip to content

Commit f2b1187

Browse files
author
Kennedy Baird
committed
fix: cast field input to Decimal
1 parent 19a734c commit f2b1187

File tree

1 file changed

+9
-2
lines changed
  • packages/core/src/fields/types/decimal

1 file changed

+9
-2
lines changed

packages/core/src/fields/types/decimal/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ function parseDecimalValueOption (meta: FieldData, value: string, name: string)
4848
return decimal
4949
}
5050

51-
export function decimal <ListTypeInfo extends BaseListTypeInfo>(config: DecimalFieldConfig<ListTypeInfo> = {}): FieldTypeFunc<ListTypeInfo> {
51+
function safeParseDecimalValueOption (meta: FieldData, value: string | null | undefined, name: string): Decimal | null | undefined {
52+
if (value === null || value === undefined) {
53+
return value
54+
}
55+
return parseDecimalValueOption(meta, value, name)
56+
}
57+
58+
export function decimal <ListTypeInfo extends BaseListTypeInfo> (config: DecimalFieldConfig<ListTypeInfo> = {}): FieldTypeFunc<ListTypeInfo> {
5259
const {
5360
isIndexed,
5461
precision = 18,
@@ -107,7 +114,7 @@ export function decimal <ListTypeInfo extends BaseListTypeInfo>(config: DecimalF
107114
} = makeValidateHook(meta, config, ({ resolvedData, operation, addValidationError }) => {
108115
if (operation === 'delete') return
109116

110-
const value: Decimal | null | undefined = resolvedData[meta.fieldKey]
117+
const value = safeParseDecimalValueOption(meta, resolvedData[meta.fieldKey], 'value')
111118
if (value != null) {
112119
if (min !== undefined && value.lessThan(min)) {
113120
addValidationError(`value must be greater than or equal to ${min}`)

0 commit comments

Comments
 (0)