From 68a64a7c4cf51e071e53a5a3710d200dc71f1c4e Mon Sep 17 00:00:00 2001 From: Alex Luckett Date: Sat, 21 Nov 2026 13:12:37 +0000 Subject: [PATCH 1/3] Add a v5 to v6 migration guide --- docs/migration-v5-to-v6.md | 105 +++++++++++++++++++++++++++++++++++++ docs/reference.md | 4 ++ 2 files changed, 109 insertions(+) create mode 100644 docs/migration-v5-to-v6.md diff --git a/docs/migration-v5-to-v6.md b/docs/migration-v5-to-v6.md new file mode 100644 index 000000000..4be0c3190 --- /dev/null +++ b/docs/migration-v5-to-v6.md @@ -0,0 +1,105 @@ +# Migrating from v5 to v6 + +This guide lists the changes you must make to move an application from `@defra/forms-engine-plugin` v5 to v6. + +In v6 the plugin's source is JavaScript with JSDoc types, not TypeScript. The plugin does the same things, and it still publishes type declarations (`.d.ts` files) for TypeScript users. `tsc` writes them from the JSDoc types. JavaScript has no syntax for some TypeScript types, so a few published types change form. Applications that use the plugin from JavaScript, or use only its plugin options and page controller methods, need no changes. + +## Breaking changes + +| Change | Applies to | Effort | +| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ------- | +| [Optional class fields are `T \| undefined`](#optional-class-fields) | TypeScript code that types a plain object as a plugin class | Trivial | +| [Interfaces are type aliases](#interfaces-are-type-aliases) | TypeScript code that adds members to the plugin's types | Small | +| [`LocationFieldBase` is not `abstract` in the types](#locationfieldbase) | Code that subclasses `LocationFieldBase` | Trivial | +| [`SchemaValidationError.cause` is enumerable](#schemavalidationerror-cause) | Code that serialises errors with `JSON.stringify` or copies their properties | Trivial | +| [`FileUploadFieldDetailitem` is renamed](#fileuploadfielddetailitem) | TypeScript code that imports `FileUploadFieldDetailitem` | Trivial | + +## Optional class fields + +JSDoc has no way to make a class field optional. A field that was `id?: string` is now `id: string | undefined` in the type declarations of these classes: + +| Class | Fields | +| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `ComponentBase` | `id`, `page`, `schema`, `options` | +| `List`, `ListFormComponent` | `list` | +| `ComponentCollection` | `page`, `parent` | +| `LocationFieldBase` | `instructionText` | +| `PageController` | `name`, `id`, `section`, `condition`, `events`, `collection` | +| `FormModel` | `engine`, `ordnanceSurveyApiKey`, `controllers` | +| `SummaryViewModel` | `declaration`, `backLink`, `feedbackLink`, `phaseTag`, `errors`, `hasMissingNotificationEmail`, `components`, `paymentState`, `paymentDetails`, `paymentRequired`, `paymentPreAuthorized` | + +Code that creates these classes with `new`, or reads their fields, works as before. A plain object typed as one of these classes must now include each field, for example in a test mock. + +Before: + +```ts +const page: PageController = { path: '/start', title: 'Start' /* … */ } +``` + +After: + +```ts +const page: PageController = { + path: '/start', + title: 'Start', + id: undefined, + name: undefined + /* … */ +} +``` + +## Interfaces are type aliases + +JavaScript has no interface declaration: every JSDoc type is a type alias. Each interface that the plugin exported is now a type alias with the same shape. This includes every type from `@defra/forms-engine-plugin/types`, such as `PluginOptions` and `FormContext`. + +Code that uses these types works as before. TypeScript code can no longer add members to them with declaration merging or module augmentation. Define your own type that extends the plugin's type instead. + +Before: + +```ts +declare module '@defra/forms-engine-plugin/types' { + interface PluginOptions { + myOption?: string + } +} +``` + +After: + +```ts +import { type PluginOptions } from '@defra/forms-engine-plugin/types' + +type MyPluginOptions = PluginOptions & { myOption?: string } +``` + +## LocationFieldBase + +JavaScript has no abstract classes. `LocationFieldBase` is no longer `abstract` in the type declarations, and its methods `getValidationConfig` and `getErrorTemplates` throw `Not implemented` if a subclass does not override them. TypeScript no longer reports a subclass that leaves them out, so check that each of your subclasses implements both methods. + +## SchemaValidationError cause + +`SchemaValidationError.cause` holds the Joi `ValidationError`, as before, but it is now an enumerable property. Code that lists an error's properties now sees it: `JSON.stringify(error)` includes the validation error, which describes the form definition. Loggers that write only an error's type, message and stack, such as `@elastic/ecs-pino-format`, are not affected. + +## FileUploadFieldDetailItem + +The type `FileUploadFieldDetailitem`, from `@defra/forms-engine-plugin/engine/types.js`, is now `FileUploadFieldDetailItem`, with a capital "I". Its shape is the same. + +Before: + +```ts +import { type FileUploadFieldDetailitem } from '@defra/forms-engine-plugin/engine/types.js' +``` + +After: + +```ts +import { type FileUploadFieldDetailItem } from '@defra/forms-engine-plugin/engine/types.js' +``` + +## Other changes to the type declarations + +These changes need no action: + +- Some type names are new, because a type defined in a JavaScript module is always exported. Examples are `FormDefinitionTranslation` and the `…Fields` types, such as `FormSubmissionErrorFields`. +- Exported arrow functions appear as `function` declarations, with the same types. +- A subclass's declaration file can leave out a method whose type equals the parent's. The method is still there, through the parent class. diff --git a/docs/reference.md b/docs/reference.md index b43ba58d5..c7b548791 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -13,3 +13,7 @@ The error classes the plugin throws when a form definition cannot be used, and t ## [Migrating from v4 to v5](./migration-v4-to-v5) The changes you must make to upgrade an application from v4 to v5. + +## [Migrating from v5 to v6](./migration-v5-to-v6) + +The changes you must make to upgrade an application from v5 to v6, where the plugin's source becomes JavaScript with JSDoc types. From 7d713917bfb2ce15cf2cd7a32cb5ab0919cbcf8d Mon Sep 17 00:00:00 2001 From: Alex Luckett Date: Tue, 24 Nov 2026 21:27:05 +0000 Subject: [PATCH 2/3] Say why class fields cannot be optional in the v5 to v6 guide A JSDoc type can still mark a property optional, as in a parameter's object type. Only a class field declared in JavaScript is always present. --- docs/migration-v5-to-v6.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migration-v5-to-v6.md b/docs/migration-v5-to-v6.md index 4be0c3190..e0ce887e4 100644 --- a/docs/migration-v5-to-v6.md +++ b/docs/migration-v5-to-v6.md @@ -16,7 +16,7 @@ In v6 the plugin's source is JavaScript with JSDoc types, not TypeScript. The pl ## Optional class fields -JSDoc has no way to make a class field optional. A field that was `id?: string` is now `id: string | undefined` in the type declarations of these classes: +A class field declared in JavaScript is always present, so JSDoc can type it but cannot make it optional. A field that was `id?: string` is now `id: string | undefined` in the type declarations of these classes: | Class | Fields | | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | From 66d9e11f522314093b16678a39597b29172e08e8 Mon Sep 17 00:00:00 2001 From: Alex Luckett Date: Wed, 25 Nov 2026 08:46:27 +0000 Subject: [PATCH 3/3] List the ADDITIONAL_IDENTIFIER type change in the v5 to v6 guide --- docs/migration-v5-to-v6.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/migration-v5-to-v6.md b/docs/migration-v5-to-v6.md index e0ce887e4..fb679a291 100644 --- a/docs/migration-v5-to-v6.md +++ b/docs/migration-v5-to-v6.md @@ -13,6 +13,7 @@ In v6 the plugin's source is JavaScript with JSDoc types, not TypeScript. The pl | [`LocationFieldBase` is not `abstract` in the types](#locationfieldbase) | Code that subclasses `LocationFieldBase` | Trivial | | [`SchemaValidationError.cause` is enumerable](#schemavalidationerror-cause) | Code that serialises errors with `JSON.stringify` or copies their properties | Trivial | | [`FileUploadFieldDetailitem` is renamed](#fileuploadfielddetailitem) | TypeScript code that imports `FileUploadFieldDetailitem` | Trivial | +| [`ADDITIONAL_IDENTIFIER` is not an enum](#additional_identifier) | TypeScript code that uses `ADDITIONAL_IDENTIFIER.Confirmation` as a type | Trivial | ## Optional class fields @@ -96,6 +97,23 @@ After: import { type FileUploadFieldDetailItem } from '@defra/forms-engine-plugin/engine/types.js' ``` +## ADDITIONAL_IDENTIFIER + +`ADDITIONAL_IDENTIFIER`, from `@defra/forms-engine-plugin/cache-service.js`, is now a read-only object rather than a TypeScript enum. Its value has not changed, so `ADDITIONAL_IDENTIFIER.Confirmation` is still `':confirmation'` and the keys the cache service writes are the same as before. As a type, `ADDITIONAL_IDENTIFIER` is now the union of its values: the string `':confirmation'` is accepted wherever that type is expected, and a member such as `ADDITIONAL_IDENTIFIER.Confirmation` can no longer be used as a type on its own. + +Before: + +```ts +const id: ADDITIONAL_IDENTIFIER.Confirmation = ADDITIONAL_IDENTIFIER.Confirmation +``` + +After: + +```ts +const id: typeof ADDITIONAL_IDENTIFIER.Confirmation = + ADDITIONAL_IDENTIFIER.Confirmation +``` + ## Other changes to the type declarations These changes need no action: