@types/govuk-frontend 5.9.0 → 5.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
govuk-frontend/README.md CHANGED
@@ -8,8 +8,8 @@ This package contains type definitions for govuk-frontend (https://github.com/al
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/govuk-frontend.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Thu, 03 Apr 2025 22:35:25 GMT
11
+ * Last updated: Wed, 23 Sep 2026 16:04:41 GMT
12
12
  * Dependencies: none
13
13
 
14
14
  # Credits
15
- These definitions were written by [Colin Rotherham](https://github.com/colinrotherham), and [Romaric Pascal](https://github.com/romaricpascal).
15
+ These definitions were written by [Colin Rotherham](https://github.com/colinrotherham), [Paul Robert Lloyd](https://github.com/paulrobertlloyd), and [Romaric Pascal](https://github.com/romaricpascal).
@@ -1,4 +1,5 @@
1
1
  import { Component } from "../component.js";
2
+ import { type CompatibleClass, type Config, type CreateAllOptions, type OnErrorCallback } from "../init.js";
2
3
 
3
4
  /**
4
5
  * Normalise string
@@ -29,7 +30,6 @@ export function normaliseString(
29
30
  *
30
31
  * @internal
31
32
  * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
32
- * @template {[keyof ConfigurationType, SchemaProperty | undefined][]} SchemaEntryType
33
33
  * @param {{ schema?: Schema<ConfigurationType>, moduleName: string }} Component - Component class
34
34
  * @param {DOMStringMap} dataset - HTML element dataset
35
35
  * @returns {ObjectNested} Normalised dataset
@@ -44,6 +44,23 @@ export function normaliseDataset<
44
44
  dataset: DOMStringMap,
45
45
  ): ObjectNested;
46
46
 
47
+ /**
48
+ * Normalise options passed to `initAll` or `createAll`
49
+ *
50
+ * @internal
51
+ * @template {CompatibleClass} ComponentClass
52
+ * @param {Config | CreateAllOptions<ComponentClass> | OnErrorCallback<ComponentClass> | Element | Document | null} [scopeOrOptions] - Scope of the document to search within, initialisation options or error callback function
53
+ * @returns {CreateAllOptions<ComponentClass>} Normalised options
54
+ */
55
+ export function normaliseOptions<ComponentClass extends CompatibleClass>(
56
+ scopeOrOptions?:
57
+ | Config
58
+ | CreateAllOptions<ComponentClass>
59
+ | OnErrorCallback<ComponentClass>
60
+ | Element
61
+ | Document
62
+ | null,
63
+ ): CreateAllOptions<ComponentClass>;
47
64
  /**
48
65
  * Config merging function
49
66
  *
@@ -106,13 +123,11 @@ export const configOverride: unique symbol;
106
123
  *
107
124
  * Centralises the behaviours shared by our components
108
125
  *
109
- * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
110
- * @template {Element & { dataset: DOMStringMap }} RootElementType
126
+ * @template {Partial<Record<keyof ConfigurationType, unknown>>} [ConfigurationType=ObjectNested]
127
+ * @template {Element & { dataset: DOMStringMap }} [RootElementType=HTMLElement]
111
128
  */
112
129
  export abstract class ConfigurableComponent<
113
- ConfigurationType extends Partial<
114
- Record<keyof ConfigurationType, unknown>
115
- > = ObjectNested,
130
+ ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>> = ObjectNested,
116
131
  RootElementType extends Element & {
117
132
  dataset: DOMStringMap;
118
133
  } = HTMLElement,
@@ -133,7 +148,6 @@ export abstract class ConfigurableComponent<
133
148
  */
134
149
  protected get config(): ConfigurationType;
135
150
 
136
- /** */
137
151
  _config: ConfigurationType;
138
152
 
139
153
  /**
@@ -1,5 +1,3 @@
1
- import { type ObjectNested } from "./configuration.js";
2
-
3
1
  /**
4
2
  * Common helpers which do not require polyfill.
5
3
  *
@@ -7,18 +5,6 @@ import { type ObjectNested } from "./configuration.js";
7
5
  * so that the polyfill can be properly tree-shaken and does not burden
8
6
  * the components that do not need that helper
9
7
  */
10
-
11
- /**
12
- * Get hash fragment from URL
13
- *
14
- * Extract the hash fragment (everything after the hash) from a URL,
15
- * but not including the hash symbol
16
- *
17
- * @param {string} url - URL
18
- * @returns {string | undefined} Fragment from URL, without the hash
19
- */
20
- export function getFragmentFromUrl(url: string): string | undefined;
21
-
22
8
  /**
23
9
  * Get GOV.UK Frontend breakpoint value from CSS custom property
24
10
  *
@@ -75,14 +61,26 @@ export function isSupported($scope?: HTMLElement | null): boolean;
75
61
  * Check for an object
76
62
  *
77
63
  * @internal
78
- * @template {Partial<Record<keyof ObjectType, unknown>>} [ObjectType=ObjectNested]
64
+ * @template {Partial<Record<keyof ObjectType, unknown>>} ObjectType
79
65
  * @param {unknown | ObjectType} option - Option to check
80
66
  * @returns {option is ObjectType} Whether the option is an object
81
67
  */
82
68
  export function isObject<
83
- ObjectType extends Partial<Record<keyof ObjectType, unknown>> = ObjectNested,
69
+ ObjectType extends Partial<Record<keyof ObjectType, unknown>>,
84
70
  >(option: unknown | ObjectType): option is ObjectType;
85
71
 
72
+ /**
73
+ * Check for valid scope
74
+ *
75
+ * @internal
76
+ * @template {Element | Document} ScopeType
77
+ * @param {unknown | ScopeType} $scope - Scope of the document to search within
78
+ * @returns {$scope is ScopeType} Whether the scope can be queried
79
+ */
80
+ export function isScope<ScopeType extends Element | Document>(
81
+ $scope: unknown | ScopeType,
82
+ ): $scope is ScopeType;
83
+
86
84
  /**
87
85
  * Format error message
88
86
  *
@@ -73,22 +73,22 @@ export class InitError extends GOVUKFrontendError {
73
73
  */
74
74
  export interface ElementErrorOptions {
75
75
  /**
76
- * - An identifier that'll let the user understand which element has an error. This is whatever makes the most sense
76
+ * - The element in error (optional)
77
77
  */
78
- identifier: string;
78
+ element?: Document | Element | null | undefined;
79
79
 
80
80
  /**
81
- * - The element in error
81
+ * - Component throwing the error (optional)
82
82
  */
83
- element?: Element | null | undefined;
83
+ component?: ComponentWithModuleName | undefined;
84
84
 
85
85
  /**
86
- * - The type that was expected for the identifier
86
+ * - An identifier that'll let the user understand which element has an error. This is whatever makes the most sense
87
87
  */
88
- expectedType?: string | undefined;
88
+ identifier: string;
89
89
 
90
90
  /**
91
- * - Component throwing the error
91
+ * - The type that was expected for the identifier (optional)
92
92
  */
93
- component: ComponentWithModuleName;
93
+ expectedType?: string | undefined;
94
94
  }
@@ -5,59 +5,6 @@
5
5
  * @internal
6
6
  */
7
7
  export class I18n {
8
- /**
9
- * Map of plural rules to languages where those rules apply.
10
- *
11
- * Note: These groups are named for the most dominant or recognisable language
12
- * that uses each system. The groupings do not imply that the languages are
13
- * related to one another. Many languages have evolved the same systems
14
- * independently of one another.
15
- *
16
- * Code to support more languages can be found in the i18n spike:
17
- * {@link https://github.com/alphagov/govuk-frontend/blob/spike-i18n-support/src/govuk/i18n.mjs}
18
- *
19
- * Languages currently supported:
20
- *
21
- * Arabic: Arabic (ar)
22
- * Chinese: Burmese (my), Chinese (zh), Indonesian (id), Japanese (ja),
23
- * Javanese (jv), Korean (ko), Malay (ms), Thai (th), Vietnamese (vi)
24
- * French: Armenian (hy), Bangla (bn), French (fr), Gujarati (gu), Hindi (hi),
25
- * Persian Farsi (fa), Punjabi (pa), Zulu (zu)
26
- * German: Afrikaans (af), Albanian (sq), Azerbaijani (az), Basque (eu),
27
- * Bulgarian (bg), Catalan (ca), Danish (da), Dutch (nl), English (en),
28
- * Estonian (et), Finnish (fi), Georgian (ka), German (de), Greek (el),
29
- * Hungarian (hu), Luxembourgish (lb), Norwegian (no), Somali (so),
30
- * Swahili (sw), Swedish (sv), Tamil (ta), Telugu (te), Turkish (tr),
31
- * Urdu (ur)
32
- * Irish: Irish Gaelic (ga)
33
- * Russian: Russian (ru), Ukrainian (uk)
34
- * Scottish: Scottish Gaelic (gd)
35
- * Spanish: European Portuguese (pt-PT), Italian (it), Spanish (es)
36
- * Welsh: Welsh (cy)
37
- *
38
- * @internal
39
- */
40
- static pluralRulesMap: {
41
- [key: string]: string[];
42
- };
43
-
44
- /**
45
- * Different pluralisation rule sets
46
- *
47
- * Returns the appropriate suffix for the plural form associated with `n`.
48
- * Possible suffixes: 'zero', 'one', 'two', 'few', 'many', 'other' (the actual
49
- * meaning of each differs per locale). 'other' should always exist, even in
50
- * languages without plurals, such as Chinese.
51
- * {@link https://cldr.unicode.org/index/cldr-spec/plural-rules}
52
- *
53
- * The count must be a positive integer. Negative numbers and decimals aren't accounted for
54
- *
55
- * @internal
56
- */
57
- static pluralRules: {
58
- [key: string]: (count: number) => PluralRule;
59
- };
60
-
61
8
  /**
62
9
  * @internal
63
10
  * @param {{ [key: string]: string | TranslationPluralForms }} translations - Key-value pairs of the translation strings to use.
@@ -142,32 +89,6 @@ export class I18n {
142
89
  * @throws {Error} Plural form `.other` required when preferred plural form is missing
143
90
  */
144
91
  getPluralSuffix(lookupKey: string, count: number): PluralRule;
145
-
146
- /**
147
- * Get the plural form using our fallback implementation
148
- *
149
- * This is split out into a separate function to make it easier to test the
150
- * fallback behaviour in an environment where Intl.PluralRules exists.
151
- *
152
- * @internal
153
- * @param {number} count - Number used to determine which pluralisation to use.
154
- * @returns {PluralRule} The pluralisation form for count in this locale.
155
- */
156
- selectPluralFormUsingFallbackRules(count: number): PluralRule;
157
-
158
- /**
159
- * Work out which pluralisation rules to use for the current locale
160
- *
161
- * The locale may include a regional indicator (such as en-GB), but we don't
162
- * usually care about this part, as pluralisation rules are usually the same
163
- * regardless of region. There are exceptions, however, (e.g. Portuguese) so
164
- * this searches by both the full and shortened locale codes, just to be sure.
165
- *
166
- * @internal
167
- * @returns {string | undefined} The name of the pluralisation rule to use (a key for one
168
- * of the functions in this.pluralRules)
169
- */
170
- getPluralRulesForLocale(): string | undefined;
171
92
  }
172
93
 
173
94
  /**
@@ -1,11 +1,14 @@
1
- import { type AccordionConfig } from "./components/accordion/accordion.js";
2
- import { type ButtonConfig } from "./components/button/button.js";
3
- import { type CharacterCountConfig } from "./components/character-count/character-count.js";
4
- import { type ErrorSummaryConfig } from "./components/error-summary/error-summary.js";
5
- import { type ExitThisPageConfig } from "./components/exit-this-page/exit-this-page.js";
6
- import { type FileUploadConfig } from "./components/file-upload/file-upload.js";
7
- import { type NotificationBannerConfig } from "./components/notification-banner/notification-banner.js";
8
- import { type PasswordInputConfig } from "./components/password-input/password-input.js";
1
+ import { Accordion, type AccordionConfig } from "./components/accordion/accordion.js";
2
+ import { Button, type ButtonConfig } from "./components/button/button.js";
3
+ import { CharacterCount, type CharacterCountConfig } from "./components/character-count/character-count.js";
4
+ import { ErrorSummary, type ErrorSummaryConfig } from "./components/error-summary/error-summary.js";
5
+ import { ExitThisPage, type ExitThisPageConfig } from "./components/exit-this-page/exit-this-page.js";
6
+ import { FileUpload, type FileUploadConfig } from "./components/file-upload/file-upload.js";
7
+ import {
8
+ NotificationBanner,
9
+ type NotificationBannerConfig,
10
+ } from "./components/notification-banner/notification-banner.js";
11
+ import { PasswordInput, type PasswordInputConfig } from "./components/password-input/password-input.js";
9
12
 
10
13
  export interface CompatibleClass {
11
14
  new(...args: any[]): any;
@@ -16,6 +19,28 @@ export interface CompatibleClass {
16
19
  * Config for all components via `initAll()`
17
20
  */
18
21
  export interface Config {
22
+ /**
23
+ * - Scope of the document to search within
24
+ */
25
+ scope?: Document | Element | null | undefined;
26
+
27
+ /**
28
+ * - Initialisation error callback
29
+ */
30
+ onError?:
31
+ | OnErrorCallback<
32
+ | typeof Accordion
33
+ | typeof Button
34
+ | typeof CharacterCount
35
+ | typeof ErrorSummary
36
+ | typeof ExitThisPage
37
+ | typeof FileUpload
38
+ | typeof NotificationBanner
39
+ | typeof PasswordInput
40
+ | undefined
41
+ >
42
+ | undefined;
43
+
19
44
  /**
20
45
  * - Accordion config
21
46
  */
@@ -60,15 +85,18 @@ export interface Config {
60
85
  /**
61
86
  * Component config keys, e.g. `accordion` and `characterCount`
62
87
  */
63
- export type ConfigKey = keyof Config;
88
+ export type ConfigKey = keyof Omit<Config, "scope" | "onError">;
64
89
 
65
90
  export type ComponentConfig<ComponentClass extends CompatibleClass> = ConstructorParameters<ComponentClass>[1];
66
91
 
67
- export interface ErrorContext<ComponentClass extends CompatibleClass> {
92
+ export interface ErrorContext<
93
+ ComponentClass extends CompatibleClass | undefined = undefined,
94
+ > {
68
95
  /**
69
96
  * - Element used for component module initialisation
70
97
  */
71
- element?: Element | undefined;
98
+ element?: ComponentClass extends CompatibleClass ? Element
99
+ : undefined;
72
100
 
73
101
  /**
74
102
  * - Class of component
@@ -76,12 +104,15 @@ export interface ErrorContext<ComponentClass extends CompatibleClass> {
76
104
  component?: ComponentClass | undefined;
77
105
 
78
106
  /**
79
- * - Config supplied to component
107
+ * - Config supplied to components
80
108
  */
81
- config: ComponentConfig<ComponentClass>;
109
+ config?: ComponentClass extends CompatibleClass ? ComponentConfig<ComponentClass>
110
+ : Config;
82
111
  }
83
112
 
84
- export type OnErrorCallback<ComponentClass extends CompatibleClass> = (
113
+ export type OnErrorCallback<
114
+ ComponentClass extends CompatibleClass | undefined = undefined,
115
+ > = (
85
116
  error: unknown,
86
117
  context: ErrorContext<ComponentClass>,
87
118
  ) => any;
@@ -90,7 +121,7 @@ export interface CreateAllOptions<ComponentClass extends CompatibleClass> {
90
121
  /**
91
122
  * - scope of the document to search within
92
123
  */
93
- scope?: Document | Element | undefined;
124
+ scope?: Document | Element | null | undefined;
94
125
 
95
126
  /**
96
127
  * - callback function if error throw by component on init
@@ -104,13 +135,10 @@ export interface CreateAllOptions<ComponentClass extends CompatibleClass> {
104
135
  * Use the `data-module` attributes to find, instantiate and init all of the
105
136
  * components provided as part of GOV.UK Frontend.
106
137
  *
107
- * @param {Config & { scope?: Element, onError?: OnErrorCallback<CompatibleClass> }} [config] - Config for all components (with optional scope)
138
+ * @param {Config | Element | Document | null} [scopeOrConfig] - Scope of the document to search within or config for all components (with optional scope)
108
139
  */
109
140
  export function initAll(
110
- config?: Config & {
111
- scope?: Element;
112
- onError?: OnErrorCallback<CompatibleClass>;
113
- },
141
+ scopeOrConfig?: Config | Element | Document | null,
114
142
  ): void;
115
143
 
116
144
  /**
@@ -125,15 +153,16 @@ export function initAll(
125
153
  * @template {CompatibleClass} ComponentClass
126
154
  * @param {ComponentClass} Component - class of the component to create
127
155
  * @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component
128
- * @param {OnErrorCallback<ComponentClass> | Element | Document | CreateAllOptions<ComponentClass> } [createAllOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
156
+ * @param {OnErrorCallback<ComponentClass> | Element | Document | null | CreateAllOptions<ComponentClass>} [scopeOrOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
129
157
  * @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components
130
158
  */
131
159
  export function createAll<ComponentClass extends CompatibleClass>(
132
160
  Component: ComponentClass,
133
161
  config?: ComponentConfig<ComponentClass>,
134
- createAllOptions?:
162
+ scopeOrOptions?:
135
163
  | OnErrorCallback<ComponentClass>
136
164
  | Element
137
165
  | Document
166
+ | null
138
167
  | CreateAllOptions<ComponentClass>,
139
168
  ): Array<InstanceType<ComponentClass>>;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/govuk-frontend",
3
- "version": "5.9.0",
3
+ "version": "5.12.0",
4
4
  "description": "TypeScript definitions for govuk-frontend",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/govuk-frontend",
6
6
  "license": "MIT",
@@ -10,6 +10,11 @@
10
10
  "githubUsername": "colinrotherham",
11
11
  "url": "https://github.com/colinrotherham"
12
12
  },
13
+ {
14
+ "name": "Paul Robert Lloyd",
15
+ "githubUsername": "paulrobertlloyd",
16
+ "url": "https://github.com/paulrobertlloyd"
17
+ },
13
18
  {
14
19
  "name": "Romaric Pascal",
15
20
  "githubUsername": "romaricpascal",
@@ -23,6 +28,10 @@
23
28
  "import": "./dist/govuk/all.d.mts",
24
29
  "require": "./dist/govuk/all.bundle.d.ts"
25
30
  },
31
+ "./*": {
32
+ "require": "./*",
33
+ "import": "./*"
34
+ },
26
35
  "./package.json": "./package.json"
27
36
  },
28
37
  "repository": {
@@ -33,6 +42,6 @@
33
42
  "scripts": {},
34
43
  "dependencies": {},
35
44
  "peerDependencies": {},
36
- "typesPublisherContentHash": "0c6bf1e47e944f9d230c1eed825ea255eb3d43f5684e51a3c8c070c2a8ec9177",
37
- "typeScriptVersion": "5.1"
45
+ "typesPublisherContentHash": "a19c43bebf5ed17923dde91177c22c487853e8024bb51649a865f2297e0211d1",
46
+ "typeScriptVersion": "5.6"
38
47
  }