Skip to content

chore: migrate plugin types to plugin #2111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

SethFalco
Copy link
Member

A significant change to how we type plugins.

Type Declaration

Instead of declaring all plugin types in plugins/plugins-types.d.ts, we declare each plugins types in the respective plugin using a JSDoc @typedef. Then we import that typedef in plugins/plugins-types.d.ts.

This keeps the types much closer to the implementation, and means when amending parameters we only need to touch one file instead of remembering to update the separate type declarations file.

I opted for using the more verbose @typedef syntax (@property {type} name) over the leaner variant ({{ name: type }}) because I prefer that the verbose syntax leaves room to document types as well. You'll see some types even had their documentation migrated over to the JSDoc as well.

Refactors

  • Changes how we do InternalParams for covertPathData. Instead, we use the Required<T> type which sets all types to non-null without us having to do it ourselves.
  • Drops the Plugin type from plugins/plugins-types.d.ts, in favor of using the type with the same name from lib/types.d.ts. With the new way we're defining types now, there is no value in keeping that one, and as we're prepping for SVGO v4, we can drop it from the public API.

Bugs

  • Fixes type definitions for removeXlink, which had the parameter defined as required when it should've been optional.

Documentation

  • Clarifies the changes above.
  • Reduces the verbosity a little, in particular the reference to code editors.

@SethFalco SethFalco merged commit 4573d01 into svg:main Apr 30, 2025
13 checks passed
@SethFalco SethFalco deleted the migrate-plugin-types-to-plugin branch April 30, 2025 01:16
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.

1 participant