import type { Context } from "koa"; import { Form } from "../forms/form.js"; import { FieldTypes } from "sealious"; import { CollectionField } from "../forms/fields/collection-field.js"; import { FormData } from "../forms/form-types.js"; describe("mountable-with-fields", () => { it("properly types the getParsedValues method and respects required status", () => { const fields = { not_required: new CollectionField(false, new FieldTypes.Text()), required: new CollectionField(true, new FieldTypes.Text()), }; new (class extends Form { getFields = () => fields; getControls = () => []; async onSubmit(ctx: Context, form_values: FormData) { const data = await this.getParsedValues(ctx); // this should not throw a Typescript error data.not_required?.trim(); // this should work without the optional chaining: data.required.trim(); const { parsed: data2 } = await this.fields.not_required.getParsedValue( ctx, form_values.raw_values ); data2?.trim(); } })(); }); });