alphagov / govuk-design-system

One place for service teams to find styles, components and patterns for designing government services.
https://www.gov.uk/design-system
MIT License
517 stars 236 forks source link

Add shorthand ambient module definition for 'govuk-frontend' #4207

Closed romaricpascal closed 1 month ago

romaricpascal commented 1 month ago

As govuk-frontend provides no types, TypeScript will type its exports as any but be unable to acknowledge fields inherited from parent classes. This leads to errors when trying to assign or use them.

TypeScript's shorthand ambient modules seem to also make inherited fields typed as any.

This "empty" module will override any other definition of the govuk-frontend module, either in another .d.ts file or in @types/govuk-frontend.

Issue was, our project was not configured to look up for .ts file, meaning any global.d.ts file was overlooked by TypeScript. Adding **/*.d.ts file to the tsconfig.json in src allows TypeScript to find the shorthand ambient module and TypeScript is happy with accessing this.$root in classes inheriting from Component 🥳

netlify[bot] commented 1 month ago

You can preview this change here:

Name Link
Latest commit a830e84f49ba589b3192d4c5030c3f02fc1bc6d7
Latest deploy log https://app.netlify.com/sites/govuk-design-system-preview/deploys/67082e8842a96c0008f54b1a
Deploy Preview https://deploy-preview-4207--govuk-design-system-preview.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.