Skip to content

Commit a4ecdcd

Browse files
committed
fix: optional fields issue
1 parent 637d2e0 commit a4ecdcd

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/ax/dsp/extract.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ export const streamingExtractFinalValue = (
7676
if (state.currField.type?.name === 'json') {
7777
values[state.currField.name] = validateAndParseJson(state.currField, val);
7878
} else {
79-
values[state.currField.name] = convertValueToType(
80-
state.currField.type?.name ?? 'string',
81-
val
82-
);
79+
values[state.currField.name] = convertValueToType(state.currField, val);
8380
}
8481
};
8582

@@ -105,11 +102,11 @@ const validateAndParseSingleValue = (
105102
}
106103
};
107104

108-
const convertValueToType = (
109-
expectedType: string,
110-
val: unknown
111-
): string | number | boolean | Date => {
112-
switch (expectedType) {
105+
const convertValueToType = (field: Readonly<AxField>, val: unknown) => {
106+
if (field.isOptional && (!val || val === '')) {
107+
return;
108+
}
109+
switch (field.type?.name) {
113110
case 'string':
114111
return val as string;
115112
case 'number':

0 commit comments

Comments
 (0)