Skip to content

DF-1509: Convert the public types, form models and engine tests to JavaScript with JSDoc - #508

Open
alexluckett wants to merge 4 commits into
chore/df-1509-serverfrom
chore/df-1509-types
Open

alexluckett wants to merge 4 commits into
chore/df-1509-serverfrom
chore/df-1509-types

Conversation

@alexluckett

@alexluckett alexluckett commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Proposed change

Part of the TypeScript to JavaScript migration (v6), this PR is stacked on the server and helpers PR and brings the changes to the published types together in one place. The package's ./types entry point, the submission message schemas, engine/types and the form models (FormModel, SummaryViewModel, the model types, index, unavailable-view-model, and the empty Section and RepeatingSummaryViewModel) are converted to JavaScript with JSDoc types, along with the 24 engine, i18n, model and output formatter tests. A final commit renames FileUploadFieldDetailitem.

  • Type imports have moved to a single @import block at the end of each file, annotations are now @type, @param and @returns, and casts are JSDoc casts.
  • The 77 type re-exports of ./types (export type { X } from '…') are now @import { X as XType } from '…' followed by @typedef {XType} X, with @template for generics. They are the same 77 names, from the same modules and in the same order as on main. In schema.js, the result of each Joi.object<X>() call is cast with /** @type {ObjectSchema<X>} */ (Joi.object()).
  • Member comments have become @property descriptions, so they now appear as hover text. Where a type extends another, its own members move into a new named typedef joined with &, which publishes four new names: FormSubmissionErrorFields, ExecutableConditionFields, DetailItemFieldFields and DetailItemRepeatFields.
  • In the FormModel constructor, def: typeof this.def is now def: FormModel['def'], which is the same type; JSDoc does not allow this in a parameter type.
  • FormModel.getReference, added on main with the payment reference fix, has been converted with the rest of the class, and its tests with FormModel.test.
  • The SummaryViewModel snapshot has been renamed along with its test (.test.ts.snap to .test.js.snap), and its content is unchanged. Jest names a snapshot after its test file.
  • Breaking:
    • Interfaces become type aliases, including every type from @defra/forms-engine-plugin/types as well as PluginOptions and FormContext, so applications can no longer augment them through declaration merging.
    • Optional class fields lose their ?, so x?: T becomes x: T | undefined on FormModel (engine, ordnanceSurveyApiKey, controllers) and SummaryViewModel (11 fields). This only affects code that types a plain object as one of these classes.
    • FileUploadFieldDetailitem is renamed FileUploadFieldDetailItem in engine/types and the output formatters. The type is published through ./engine/*, and since v6 is a major release, this is the right time to correct the name. The v5 to v6 guide describes the rename.
  • In the tests, two imports from ./helpers.js in helpers.test.js have been merged into one, which is the only runtime change in the tests. Two this: parameters inside function types are kept as written.
  • src/typings/hapi and src/typings/joi now import engine/types.js, and the jest.mock paths in form-context.test name models/index.js.

Apart from the merged test import and the removed export {} lines, the compiled code is identical to main. The full test suite gives the same results as on main (2,583 passed, 13 skipped).

Jira ticket: DF-1509

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Misc. (documentation, build updates, etc)

Checklist

  • You have executed this code locally and it performs as expected.
  • You have added tests to verify your code works.
  • You have added code comments and JSDoc, where appropriate.
  • There is no commented-out code.
  • You have added developer docs in README.md and docs/* (where appropriate, e.g. new features).
  • The tests are passing (npm run test).
  • The linting checks are passing (npm run lint).
  • The code has been formatted (npm run format).

@alexluckett
alexluckett added this pull request to stack #513 November 24, 2026 21:27
FormModel, SummaryViewModel, the model type modules and engine/types are
now .js files typed with JSDoc and checked by tsc. Members with a comment
in the source become @Property lines with that comment as description.
The typings, a jest mock and a comment refer to the new .js paths.
The type is published through ./engine/* in v5, with a lowercase "i".
v6 is a major release, so it takes the corrected name now rather than
in a later breaking release. The v5 to v6 guide lists the rename.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
7 New Major Issues (required ≤ 0)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

import { logger } from '~/src/server/common/helpers/logging/logger.js'
import { EN_GB } from '~/src/server/constants.js'
import { type ListFormComponent } from '~/src/server/plugins/engine/components/ListFormComponent.js'
import {} from '~/src/server/plugins/engine/components/YesNoField.js'

@jbarnsley10 jbarnsley10 Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing this (import without specifier)?

@jbarnsley10 jbarnsley10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Lots of Sonar issues if we want to fix them.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants