Repository navigation
feat(plugin): type custom Plugin props and resolve experimental types under node resolution - #1448
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…peScript hosts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ntal types with node resolution - make Plugin generic over the plugin's props: <Plugin<MyProps> ... /> type-checks custom props; without a type argument any custom props are accepted (previously they were rejected by the compiler even though they are forwarded at runtime) - declare onError and showAlertsInPlugin, which are forwarded to and handled by the plugin wrapper - export PluginProps and PluginComponentProps from @dhis2/app-runtime/experimental - add typesVersions so '@dhis2/app-runtime/experimental' resolves with "moduleResolution": "node" (the create-app template default) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KaiVandivier
left a comment
There was a problem hiding this comment.
Nice! 🙌
I had Claude AI do a review, and I pushed a couple fixes for these things:
-
The "Older versions" note in the docs is never closed: docs/components/Plugin.md:99. The closing
:::sits at the start of a text line (::: For the props passed by the core apps, ...). Docusaurus only closes the box when:::is alone on its line. As written, the rest of the page, including "Extended example", renders inside the box, or the build warns. Put:::on its own line, then a blank line. The "core apps" paragraph probably belongs outside the note anyway. -
A props type written as an
interfaceis rejected: services/plugin/src/Plugin.tsx:102, and the same constraint at line 78.TPluginProps extends Record<string, unknown>only acceptstypealiases, because interfaces have no index signature. For example,interface P { foo: string }with<Plugin<P> ... />fails with TS2344 ("Index signature for type 'string' is missing"). Many codebases write props as interfaces by default. Loosening the constraint toobject(orRecord<string, any>) on both lines fixes it. -
The "Older versions" note doesn't name a version: Plugin.md:98. "Before this change" means nothing to someone reading the published docs. Naming the release (for example "Before vX.Y.Z") tells readers whether they still need the
React.FCcast.
Then there were these minor things -- they could maybe be improved, but not sure if they're important; I'll leave it up to you:
-
Some custom prop names compile but are silently replaced: Plugin.tsx:180. The affected names are
alertsAdd,setPluginHeight,setPluginWidthandsetInErrorState. They aren't blocked by the type the wayPluginPropskeys are, but the host's own values are spread over them before the props reach the iframe. Either exclude them in the type (Partial<Record<..., never>>) or document them as reserved. -
The
experimentalfix only covers types: runtime/package.json:20. The newtypesVersionsentry makes@dhis2/app-runtime/experimentaltype-check withmoduleResolution: node. But there is still noexperimental/folder orexperimental.jsat the package root, so tools that ignore theexportsfield still can't load the JavaScript. Examples are Jest before v28 and webpack 4: the import compiles, then fails at run time with "Cannot find module". Add a rootexperimental/package.jsonthat points tobuild/cjsandbuild/es, or say in the docs that only the types are fixed.
@commitlint/config-conventional 21.3.0 adds the header-breaking-change rule, which the commitlint bundled in JulienKode/pull-request-name-linter-action@v20.1.0 does not implement, so lint-pr-title fails on every pull request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
# [3.18.0](v3.17.6...v3.18.0) (2026-12-02) ### Features * **plugin:** type custom Plugin props and resolve experimental types under node resolution ([#1448](#1448)) ([3f10d24](3f10d24))
|
🎉 This PR is included in version 3.18.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |



Why
Two problems hit TypeScript apps that host a plugin with
<Plugin>:Pluginforwards any extra props to the plugin at runtime, but its type only declares the built-in ones. So<Plugin pluginShortName="x" orgUnitId={id} />fails to compile, and hosts end up casting.@dhis2/app-runtime/experimentaldoesn't resolve under"moduleResolution": "node", which is the default in create-app's TypeScript templates. That resolution mode ignores packageexports, so tsc can't find the subpath's types.Changes
Pluginis now generic over the plugin's props.<Plugin<FacilityMapProps> pluginShortName="facility-map" orgUnitId={id} onSelect={onSelect} />checks the custom props. Without a type argument, any custom props are accepted, so existing code keeps compiling.onErrorandshowAlertsInPluginare now part of the props type. Both were already forwarded to the plugin and handled by its wrapper.propsToPassNonMemoized?: anyis removed from the public type.PluginPropsandPluginComponentPropsare exported from@dhis2/app-runtime/experimental.runtime/package.jsongets atypesVersionsentry forexperimental, so the subpath's types resolve undernoderesolution too.docs/components/Plugin.mdexplains which props reach the plugin (the plugin-side loader strips the internal ones), documents<Plugin<MyProps>>, and keeps a note on workarounds for older versions.Testing
"moduleResolution": "node"and"bundler". A wrong prop type and a missing prop are caught as errors (checked with@ts-expect-error), and untyped usage still compiles.Related PRs
Part of a set that makes DHIS2 plugins (Capture form field / enrollment / bulk data entry, Dashboard) easier to build, and brings the docs in line with what the host apps actually pass:
<Plugin>custom props,experimentaltypes undernoderesolution@/aliases and@dhis2/app-runtime/experimentalpnpm create @dhis2/app --template plugin --pluginType <type>dhis2-pluginsagent skill🤖 Generated with Claude Code