Skip to content

DF-1509: Convert the foundation, server, engine helper and i18n modules to JavaScript with JSDoc - #507

Open
alexluckett wants to merge 6 commits into
chore/df-1509-testsfrom
chore/df-1509-server
Open

alexluckett wants to merge 6 commits into
chore/df-1509-testsfrom
chore/df-1509-server

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 tests PR and converts 52 source files to JavaScript with JSDoc types, in six commits: one for each area below, and a small second commit on the server area that names destructured parameters param0, as the other converted files do.

  • foundation (17 files): config, the logging helpers, the crumb, errorPages, pulse and session plugins, schemas, utils, httpService, the services index, the index, public and dummy-api routes, and notifyService;
  • server (11 files): src/index, src/server/index, src/server/types, the engine plugin, configureEnginePlugin and index, and the engine routes;
  • engine helpers (10 files): helpers, form-context, date-helper, form-availability, validationHelpers, referenceNumbers, registrationOptions, unavailable-response, vision and the __stubs__/definitions fixture;
  • i18n and output formatters (13 files);
  • cache service (1 file): cacheService.

Key changes:

  • 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.
  • JavaScript cannot pass type arguments to calls such as Joi.string<T>() or request<BodyType>(…), so the result or the function is cast instead. config/index.js has 17 of these SchemaObj casts.
  • Some declarations need an explicit type so that tsc publishes them in the same form as before. requestLogger and the exported engine plugin have a @type, which keeps them as constants rather than a namespace. getPage and findPage have @returns {PageControllerClass}, so the published type is the alias rather than a list of seven controller classes. The overloads of getPageHref are now @overload blocks with the same signatures.
  • i18n/types.js publishes a new type, FormDefinitionTranslation. A nested type contained a // comment, which a JSDoc type cannot hold, so the nested type has become a typedef of its own and the comment is now the description of components, word for word.
  • In outputFormatters/index.js the version keys have lost their quotes ('1': formatHumanV1 is now 1: formatHumanV1), as Prettier does for JavaScript. Object keys are always strings, so getFormatter(audience, '1') still finds the same function.
  • In __stubs__/definitions.js, a line that started with a cast has been split into a const and an assignment, because Prettier removes the parentheses of a JSDoc cast at the start of a line. The same object is assigned.
  • helpers.ts had an @import comment part-way through the file, which has been merged into the block at the end.
  • Breaking: interfaces become type aliases, so they can no longer be extended through declaration merging. This affects the five types in src/server/types (FormsService, FormSubmissionService, Services, RouteConfig, OutputService), eight engine types (OfflineBoomData, GlobalScope, FormVersionMetadata, FormModelOptions, FormContextOptions, ExternalComponent, CompileOptions, EngineConfigurationObject) and Translator.
  • Because every typedef in a JavaScript module is exported, some names are now published: JourneyState, SummaryRequest, CompileOptions, EntityTranslations, BaseTranslations, Formatter, FileUploadFieldDetailitem (in machine/v1) and PaymentOutput. The default exports of errorPages, pulse and session appear as a namespace, but these files are not in the package exports map.
  • cacheService exports ADDITIONAL_IDENTIFIER as a read-only object with a type of the same name, rather than a TypeScript enum, because JavaScript has no enums. A string enum already compiles to an object with the same key and value, so ADDITIONAL_IDENTIFIER.Confirmation is still ':confirmation' and the keys written to the cache are unchanged. Breaking: as a type, ADDITIONAL_IDENTIFIER is now the union of its values, so ADDITIONAL_IDENTIFIER.Confirmation can no longer be used as a type on its own. The v5 to v6 guide describes this.
  • Paths have been updated to .js. The server:watch:dev and server:watch:debug scripts in package.json now start ./src/index.js, and the same change has been made to the jest.mock paths in 23 test files, docs/features/configuration-based/page-events.md and pageControllers/README.md. The logger-options and notify tests have moved to .js with their modules and are otherwise unchanged.

Apart from the __stubs__/definitions.js fixture, the unquoted keys, the ADDITIONAL_IDENTIFIER object 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).

The engine helpers, form context, date helper, form availability, reference
numbers, registration options, unavailable response, validation helpers,
vision setup and the definition stubs are now .js files typed with JSDoc and
checked by tsc. getPage and findPage name PageControllerClass in their return
type, so that the published types keep the alias. The tests that mock these
modules and the page controllers README refer to the new .js paths.
@alexluckett
alexluckett added this pull request to stack #513 November 24, 2026 21:27
ADDITIONAL_IDENTIFIER becomes a read-only object with a type of the same
name, rather than a TypeScript enum. Its runtime value is the same, so
the cache keys do not change; only the published type changes, as the
v5 to v6 guide describes.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
15 New Critical Issues (required ≤ 0)
38 New Major Issues (required ≤ 0)

See analysis details on SonarQube Cloud

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

* and appropriate namespaces for loading of form-specific translations later
* @param formEnGb
* @param {BaseTranslations} formEnGb
* @returns

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.

Missing return type

type FormMetadata,
type SubmitResponsePayload
} from '@defra/forms-model'
import { addDays, format as dateFormat } from 'date-fns'

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.

Were we going to remove the formatters since they're now in notify-listener? Do any plugin users make use of them?

* Returns the "files" section of the response body
* @param item - the file upload item in the form
* @param {FileUploadFieldDetailitem} item - the file upload item in the form
* @returns the file upload data

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.

Should we have a return type here?

* Returns the "repeaters" section of the response body
* @param item - the repeater item
* @param {DetailItemRepeat} item - the repeater item
* @returns the repeater item

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.

Missing return type?

@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.

Looks good in terms of type replacements.
A large number of Sonar issues - do we address them as part of tech debt later, or just leave?
Quite a number of missing return types - not sure if you'd prefer to add them (generally missing when the TS had the return type missing).
This would have taken you weeks - without AI

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