Skip to content

Commit c32d133

Browse files
🤖 Merge PR DefinitelyTyped#72124 [@types/govuk-frontend] Update for GOV.UK Frontend v5.9.0 by @colinrotherham
1 parent 98e6d36 commit c32d133

30 files changed

+264
-76
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
export { ConfigurableComponent } from "./common/configuration.mjs";
22
export { version } from "./common/govuk-frontend-version.mjs";
33
export { isSupported } from "./common/index.mjs";
4+
export { Component } from "./component.mjs";
45
export { Accordion } from "./components/accordion/accordion.mjs";
56
export { Button } from "./components/button/button.mjs";
67
export { CharacterCount } from "./components/character-count/character-count.mjs";
78
export { Checkboxes } from "./components/checkboxes/checkboxes.mjs";
89
export { ErrorSummary } from "./components/error-summary/error-summary.mjs";
910
export { ExitThisPage } from "./components/exit-this-page/exit-this-page.mjs";
11+
export { FileUpload } from "./components/file-upload/file-upload.mjs";
1012
export { Header } from "./components/header/header.mjs";
1113
export { NotificationBanner } from "./components/notification-banner/notification-banner.mjs";
1214
export { PasswordInput } from "./components/password-input/password-input.mjs";
1315
export { Radios } from "./components/radios/radios.mjs";
1416
export { ServiceNavigation } from "./components/service-navigation/service-navigation.mjs";
1517
export { SkipLink } from "./components/skip-link/skip-link.mjs";
1618
export { Tabs } from "./components/tabs/tabs.mjs";
17-
export { GOVUKFrontendComponent as Component } from "./govuk-frontend-component.mjs";
1819
export { type Config, type ConfigKey, createAll, initAll } from "./init.mjs";

‎types/govuk-frontend/dist/govuk/all.bundle.d.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { ConfigurableComponent } from "./common/configuration.js";
22
import { version } from "./common/govuk-frontend-version.js";
33
import { isSupported } from "./common/index.js";
4+
import { Component } from "./component.js";
45
import { Accordion } from "./components/accordion/accordion.js";
56
import { Button } from "./components/button/button.js";
67
import { CharacterCount } from "./components/character-count/character-count.js";
78
import { Checkboxes } from "./components/checkboxes/checkboxes.js";
89
import { ErrorSummary } from "./components/error-summary/error-summary.js";
910
import { ExitThisPage } from "./components/exit-this-page/exit-this-page.js";
11+
import { FileUpload } from "./components/file-upload/file-upload.js";
1012
import { Header } from "./components/header/header.js";
1113
import { NotificationBanner } from "./components/notification-banner/notification-banner.js";
1214
import { PasswordInput } from "./components/password-input/password-input.js";
1315
import { Radios } from "./components/radios/radios.js";
1416
import { ServiceNavigation } from "./components/service-navigation/service-navigation.js";
1517
import { SkipLink } from "./components/skip-link/skip-link.js";
1618
import { Tabs } from "./components/tabs/tabs.js";
17-
import { GOVUKFrontendComponent as Component } from "./govuk-frontend-component.js";
1819
import { type Config as ConfigImport, type ConfigKey as ConfigKeyImport, createAll, initAll } from "./init.js";
1920

2021
declare namespace GOVUKFrontend {
@@ -31,6 +32,7 @@ declare const GOVUKFrontend: {
3132
Checkboxes: typeof Checkboxes;
3233
ErrorSummary: typeof ErrorSummary;
3334
ExitThisPage: typeof ExitThisPage;
35+
FileUpload: typeof FileUpload;
3436
Header: typeof Header;
3537
NotificationBanner: typeof NotificationBanner;
3638
PasswordInput: typeof PasswordInput;

‎types/govuk-frontend/dist/govuk/common/closest-attribute-value.d.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
* @param {string} attributeName - The name of the attribute
77
* @returns {string | null} Attribute value
88
*/
9-
export function closestAttributeValue($element: Element, attributeName: string): string | null;
9+
export function closestAttributeValue(
10+
$element: Element,
11+
attributeName: string,
12+
): string | null;

‎types/govuk-frontend/dist/govuk/common/configuration.d.ts‎

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GOVUKFrontendComponent } from "../govuk-frontend-component.js";
1+
import { Component } from "../component.js";
22

33
/**
44
* Normalise string
@@ -28,13 +28,17 @@ export function normaliseString(
2828
* optionally expanding nested `i18n.field`
2929
*
3030
* @internal
31-
* @param {{ schema?: Schema<ObjectNested>, moduleName: string }} Component - Component class
31+
* @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
32+
* @template {[keyof ConfigurationType, SchemaProperty | undefined][]} SchemaEntryType
33+
* @param {{ schema?: Schema<ConfigurationType>, moduleName: string }} Component - Component class
3234
* @param {DOMStringMap} dataset - HTML element dataset
3335
* @returns {ObjectNested} Normalised dataset
3436
*/
35-
export function normaliseDataset(
37+
export function normaliseDataset<
38+
ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
39+
>(
3640
Component: {
37-
schema?: Schema<ObjectNested>;
41+
schema?: Schema<ConfigurationType>;
3842
moduleName: string;
3943
},
4044
dataset: DOMStringMap,
@@ -51,9 +55,9 @@ export function normaliseDataset(
5155
* @returns {{ [key: string]: unknown }} A merged config object
5256
*/
5357
export function mergeConfigs(
54-
...configObjects: Array<{
58+
...configObjects: {
5559
[key: string]: unknown;
56-
}>
60+
}[]
5761
): {
5862
[key: string]: unknown;
5963
};
@@ -73,13 +77,8 @@ export function mergeConfigs(
7377
* @returns {string[]} List of validation errors
7478
*/
7579
export function validateConfig<
76-
ConfigurationType extends Partial<
77-
Record<keyof ConfigurationType, unknown>
78-
>,
79-
>(
80-
schema: Schema<ConfigurationType>,
81-
config: ConfigurationType,
82-
): string[];
80+
ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
81+
>(schema: Schema<ConfigurationType>, config: ConfigurationType): string[];
8382

8483
/**
8584
* Extracts keys starting with a particular namespace from dataset ('data-*')
@@ -93,9 +92,7 @@ export function validateConfig<
9392
* @returns {ObjectNested | undefined} Nested object with dot-separated key namespace removed
9493
*/
9594
export function extractConfigByNamespace<
96-
ConfigurationType extends Partial<
97-
Record<keyof ConfigurationType, unknown>
98-
>,
95+
ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
9996
>(
10097
schema: Schema<ConfigurationType>,
10198
dataset: DOMStringMap,
@@ -109,8 +106,8 @@ export const configOverride: unique symbol;
109106
*
110107
* Centralises the behaviours shared by our components
111108
*
112-
* @template {Partial<Record<keyof ConfigurationType, unknown>>} [ConfigurationType=ObjectNested]
113-
* @template {Element & { dataset: DOMStringMap }} [RootElementType=HTMLElement]
109+
* @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
110+
* @template {Element & { dataset: DOMStringMap }} RootElementType
114111
*/
115112
export abstract class ConfigurableComponent<
116113
ConfigurationType extends Partial<
@@ -119,7 +116,7 @@ export abstract class ConfigurableComponent<
119116
RootElementType extends Element & {
120117
dataset: DOMStringMap;
121118
} = HTMLElement,
122-
> extends GOVUKFrontendComponent<RootElementType> {
119+
> extends Component<RootElementType> {
123120
/**
124121
* Constructs a new component, validating that GOV.UK Frontend is supported
125122
*
@@ -154,7 +151,9 @@ export abstract class ConfigurableComponent<
154151
* @param {Partial<ConfigurationType>} [param] - Configuration object
155152
* @returns {Partial<ConfigurationType>} return - Configuration object
156153
*/
157-
[configOverride](param?: Partial<ConfigurationType>): Partial<ConfigurationType>;
154+
[configOverride](
155+
param?: Partial<ConfigurationType>,
156+
): Partial<ConfigurationType>;
158157
}
159158

160159
export type NestedKey = keyof ObjectNested;
@@ -167,9 +166,7 @@ export interface ObjectNested {
167166
* Schema for component config
168167
*/
169168
export interface Schema<
170-
ConfigurationType extends Partial<
171-
Record<keyof ConfigurationType, unknown>
172-
>,
169+
ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
173170
> {
174171
/**
175172
* - Schema properties
@@ -179,7 +176,7 @@ export interface Schema<
179176
/**
180177
* - List of schema conditions
181178
*/
182-
anyOf?: SchemaCondition[] | undefined;
179+
anyOf?: SchemaCondition<ConfigurationType>[] | undefined;
183180
}
184181

185182
/**
@@ -195,11 +192,13 @@ export interface SchemaProperty {
195192
/**
196193
* Schema condition for component config
197194
*/
198-
export interface SchemaCondition {
195+
export interface SchemaCondition<
196+
ConfigurationType extends Partial<Record<keyof ConfigurationType, unknown>>,
197+
> {
199198
/**
200199
* - List of required config fields
201200
*/
202-
required: string[];
201+
required: (keyof ConfigurationType)[];
203202

204203
/**
205204
* - Error message when required config fields not provided

‎types/govuk-frontend/dist/govuk/common/index.d.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ export function isSupported($scope?: HTMLElement | null): boolean;
8181
*/
8282
export function isObject<
8383
ObjectType extends Partial<Record<keyof ObjectType, unknown>> = ObjectNested,
84-
>(
85-
option: unknown,
86-
): option is ObjectType;
84+
>(option: unknown | ObjectType): option is ObjectType;
8785

8886
/**
8987
* Format error message
@@ -93,7 +91,10 @@ export function isObject<
9391
* @param {string} message - Error message
9492
* @returns {string} - Formatted error message
9593
*/
96-
export function formatErrorMessage(Component: ComponentWithModuleName, message: string): string;
94+
export function formatErrorMessage(
95+
Component: ComponentWithModuleName,
96+
message: string,
97+
): string;
9798

9899
export interface ComponentWithModuleName {
99100
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./component.js";

types/govuk-frontend/dist/govuk/govuk-frontend-component.d.ts renamed to types/govuk-frontend/dist/govuk/component.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
* Base Component class
33
*
44
* Centralises the behaviours shared by our components
5+
*
6+
* @template {Element} [RootElementType=HTMLElement]
57
*/
6-
export abstract class GOVUKFrontendComponent<RootElementType extends Element = HTMLElement> {
8+
export abstract class Component<RootElementType extends Element = HTMLElement> {
79
static elementType: typeof Element;
810

911
/**

‎types/govuk-frontend/dist/govuk/components/accordion/accordion.d.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { ConfigurableComponent } from "../../common/configuration.js";
1212
* The state of each section is saved to the DOM via the `aria-expanded`
1313
* attribute, which also provides accessibility.
1414
*/
15-
export class Accordion extends ConfigurableComponent<AccordionConfig, HTMLElement> {
15+
export class Accordion extends ConfigurableComponent<
16+
AccordionConfig,
17+
HTMLElement
18+
> {
1619
/**
1720
* Name for the component used when initialising using data-module attributes.
1821
*/
@@ -22,13 +25,15 @@ export class Accordion extends ConfigurableComponent<AccordionConfig, HTMLElemen
2225
* Accordion default config
2326
*
2427
* @see {@link AccordionConfig}
28+
* @constant
2529
*/
2630
static defaults: AccordionConfig;
2731

2832
/**
2933
* Accordion config schema
3034
*
31-
* @satisfies {Schema}
35+
* @constant
36+
* @satisfies {Schema<AccordionConfig>}
3237
*/
3338
static schema: Readonly<{
3439
properties: {

‎types/govuk-frontend/dist/govuk/components/button/button.d.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ export class Button extends ConfigurableComponent<ButtonConfig, HTMLElement> {
1313
* Button default config
1414
*
1515
* @see {@link ButtonConfig}
16+
* @constant
1617
*/
1718
static defaults: ButtonConfig;
1819

1920
/**
2021
* Button config schema
2122
*
22-
* @satisfies {Schema}
23+
* @constant
24+
* @satisfies {Schema<ButtonConfig>}
2325
*/
2426
static schema: Readonly<{
2527
properties: {

‎types/govuk-frontend/dist/govuk/components/character-count/character-count.d.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { type TranslationPluralForms } from "../../i18n.js";
1111
* You can configure the message to only appear after a certain percentage
1212
* of the available characters/words has been entered.
1313
*/
14-
export class CharacterCount extends ConfigurableComponent<CharacterCountConfig, HTMLElement> {
14+
export class CharacterCount extends ConfigurableComponent<
15+
CharacterCountConfig,
16+
HTMLElement
17+
> {
1518
/**
1619
* Name for the component used when initialising using data-module attributes.
1720
*/
@@ -21,13 +24,15 @@ export class CharacterCount extends ConfigurableComponent<CharacterCountConfig,
2124
* Character count default config
2225
*
2326
* @see {@link CharacterCountConfig}
27+
* @constant
2428
*/
2529
static defaults: CharacterCountConfig;
2630

2731
/**
2832
* Character count config schema
2933
*
30-
* @satisfies {Schema}
34+
* @constant
35+
* @satisfies {Schema<CharacterCountConfig>}
3136
*/
3237
static schema: Readonly<{
3338
properties: {
@@ -44,10 +49,16 @@ export class CharacterCount extends ConfigurableComponent<CharacterCountConfig,
4449
type: "number";
4550
};
4651
};
47-
anyOf: Array<{
48-
required: string[];
49-
errorMessage: string;
50-
}>;
52+
anyOf: (
53+
| {
54+
required: "maxwords"[];
55+
errorMessage: string;
56+
}
57+
| {
58+
required: "maxlength"[];
59+
errorMessage: string;
60+
}
61+
)[];
5162
}>;
5263

5364
/**

0 commit comments

Comments
 (0)