Skip to content

DF-1509: Convert the page controllers and their helpers to JavaScript with JSDoc - #510

Open
alexluckett wants to merge 2 commits into
chore/df-1509-errorsfrom
chore/df-1509-controllers
Open

alexluckett wants to merge 2 commits into
chore/df-1509-errorsfrom
chore/df-1509-controllers

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 error classes PR and converts the 17 page controller files to JavaScript with JSDoc types, in two commits. The first covers the base controllers (PageController, QuestionPageController, StartPageController, StatusPageController, TerminalPageController), index, validationOptions and pageControllers/helpers/; the second covers FileUploadPageController, RepeatPageController, SummaryPageController and the controller test stubs in pageControllers/__stubs__/. Applications extend these classes for their custom page controllers.

  • 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.
  • pageDef was narrowed with declare on StatusPageController, TerminalPageController, FileUploadPageController, RepeatPageController and SummaryPageController. JavaScript has no declare, so on each of these classes pageDef is now a typed field that takes the value set by the parent constructor, pageDef = this.pageDef, with // @ts-expect-error TS2729: the base constructor has already set it. The published types are the same as with declare, and pageDef holds the same object after construction.
  • fileUpload and repeat, which no parent declares, are plain typed fields without a value and are set by the constructor. These fields were already present in the compiled code.
  • Where a constructor assigns an inherited field (collection and viewName in SummaryPageController, viewName in FileUploadPageController), the value is cast to the inherited type, for example /** @type {QuestionPageController['collection']} */. Without the cast, JavaScript would give the subclass field a different, inferred type.
  • private and protected are now @private and @protected, and the published types keep the modifiers. Getters keep get and gain @returns.
  • makePostRouteHandler on PageController and TerminalPageController only throws, but declares the return type that subclasses implement. It keeps its @returns, with // eslint-disable-next-line jsdoc/require-returns-check and the reason.
  • createPage has @returns {PageControllerClass}, so that tsc does not write the return type out as a list of seven controller classes. flashedErrors in QuestionPageController has a type, because in JavaScript an empty array [] would be any[].
  • Breaking: the optional fields on PageController lose their ?, so name, id, section, condition, events and collection become T | undefined. This only affects code that types a plain object as a PageController.
  • Where an override has the same type as the parent's (allowSaveAndExit, getErrors, getState, some constructors and route handlers), tsc leaves it out of the published types. The methods are still available through the parent class.
  • form-context.test.js now mocks pageControllers/index.js, and docs/features/code-based/components.md refers to SummaryPageController.js.

Apart from the five pageDef = this.pageDef 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
@alexluckett
alexluckett force-pushed the chore/df-1509-controllers branch from 28baf21 to 81f112e Compare November 25, 2026 09:03
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
10 New Critical Issues (required ≤ 0)
19 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

@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 other than many Sonar issues

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