diff --git a/packages/core/js-client/src/compilerSupport/__test__/conversion.spec.ts b/packages/core/js-client/src/compilerSupport/__test__/conversion.spec.ts index fef9ed24..946432b7 100644 --- a/packages/core/js-client/src/compilerSupport/__test__/conversion.spec.ts +++ b/packages/core/js-client/src/compilerSupport/__test__/conversion.spec.ts @@ -179,6 +179,7 @@ describe("Conversion from aqua to typescript", () => { test.each` aqua | ts | type ${1} | ${1} | ${i32} + ${null} | ${null} | ${opt_i32} ${[]} | ${null} | ${opt_i32} ${[1]} | ${1} | ${opt_i32} ${[1, 2, 3]} | ${[1, 2, 3]} | ${array_i32} @@ -205,7 +206,11 @@ describe("Conversion from aqua to typescript", () => { // assert expect(tsFromAqua).toStrictEqual(ts); - expect(aquaFromTs).toStrictEqual(aqua); + + // 'null' -> 'null' -> [] ; 'null' not equal [] + if (aqua !== null || ts !== null) { + expect(aquaFromTs).toStrictEqual(aqua); + } }, ); }); diff --git a/packages/core/js-client/src/compilerSupport/conversions.ts b/packages/core/js-client/src/compilerSupport/conversions.ts index db30dffa..68ce8865 100644 --- a/packages/core/js-client/src/compilerSupport/conversions.ts +++ b/packages/core/js-client/src/compilerSupport/conversions.ts @@ -102,11 +102,11 @@ export function aqua2js( if (schema.tag === "nil") { return null; } else if (schema.tag === "option") { - if (!Array.isArray(value)) { - throw new SchemaValidationError(path, schema, "array", value); + if (!Array.isArray(value) && value !== null) { + throw new SchemaValidationError(path, schema, "array or null", value); } - if ("0" in value) { + if (value !== null && "0" in value) { return aqua2js(value[0], schema.type, { path: [...path, "?"] }); } else { return null;