Skip to content

DF-1509: Convert the component classes and helpers to JavaScript with JSDoc - #511

Open
alexluckett wants to merge 1 commit into
chore/df-1509-controllersfrom
chore/df-1509-components
Open

alexluckett wants to merge 1 commit into
chore/df-1509-controllersfrom
chore/df-1509-components

Conversation

@alexluckett

@alexluckett alexluckett commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Proposed change

This is the last conversion PR of the TypeScript to JavaScript migration (v6). Stacked on the page controllers PR, it converts the 45 files in engine/components/ and components/helpers/ to JavaScript with JSDoc types. These files make up the published ./components API, and since every component inherits fields from its parent class, this is the PR most likely to need discussion.

  • 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.
  • 78 inherited fields in 30 files were narrowed with declare. JavaScript has no type-only field, and a field without a value would reset the inherited value to undefined after super(), so each field takes the value the parent constructor has already set:
    /** @type {OsGridRefFieldComponent['options']} */
    // @ts-expect-error TS2729: the base constructor has already set it
    options = this.options
    The published types are the same as with declare. The @ts-expect-error covers only that one false error, and tsc will report it as unused if the error ever goes away. None of these names is defined as a getter or setter on a parent class, and every component class is built with the same values and property descriptors as on main.
  • Fields that no parent declares (limits on CheckboxesField, FileUploadField and GeospatialField, and content and declarationConfirmationLabel on DeclarationField) are now plain typed fields, set by the constructor. On DeclarationField this changes the order of its own properties, but not their values.
  • Where a constructor assigns an inherited field (TrackingField.schema, EmailAddressField.formSchema and stateSchema), the value is cast to the inherited type; otherwise JavaScript would give the subclass field a different, inferred type.
  • PaymentField includes the payment reference fix from main: the reference comes from model.getReference(state, request), and the payment metadata is { formId, language }.
  • Breaking:
    • Optional fields lose their ?, so x?: T becomes x: T | undefined on ComponentBase (id, page, schema, options), List and ListFormComponent (list), ComponentCollection (page, parent) and LocationFieldBase (instructionText). This only affects code that types a plain object as one of these classes.
    • LocationFieldBase is no longer abstract in the types. The class has @abstract, and getValidationConfig and getErrorTemplates are now stubs that throw Not implemented. Both methods are implemented by OsGridRefField and NationalGridFieldNumberField, and the two stub lines are not covered by tests.
    • Interfaces become type aliases, including ViewModel, Label, ListItem, the *State types and UkAddressState.
  • DateInputItem uses @property descriptions like the other types, and its member comment stays on prefix, where it was in the source. The // Submission data comments after union members in getAnswer and getAnswerMarkdown have moved into the [options] description.
  • Where an override has the same type as the parent's, such as getAllPossibleErrors, tsc leaves it out of the published types; the method is still available through the parent class.
  • answer.test.js and generate-component-previews.test.js now mock helpers/components.js, and sonar-project.properties refers to DatePartsField.js and MonthYearField.js.

The compiled code differs from main only in the 78 field lines, the 5 plain field declarations, the 2 LocationFieldBase stubs and 2 type-only modules that no longer emit export {}. 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-components branch from 476248f to 019b8c1 Compare November 25, 2026 09:03
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)
31 New Major Issues (required ≤ 0)
27 New Critical 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 (apart from the number of Sonar issues). Approving in principle

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