Skip to content

Conversation

@rak-phillip
Copy link
Member

@rak-phillip rak-phillip commented Dec 10, 2025

Summary

This updates the Rancher Shell type generation to include the i18n plugin.

Occurred changes and/or fixed issues

  • Add the i18n plugin to the typegen script
  • Annotate stringFor() with a dostring to include types
  • Fix typescript warnings in the t() function of useI18n

Technical notes summary

Kubewarden UI will fail with the following error when updating to the latest versions of @rancher/shell:

  ERROR in node_modules/@rancher/shell/composables/useI18n.ts:3:27
  TS7016: Could not find a declaration file for module '@shell/plugins/i18n'.
  '/home/phillip/Development/kubewarden-ui/node_modules/@rancher/shell/plugins/i18n.j
  s' implicitly has an 'any' type.
    If the '@rancher/shell' package actually exposes this module, try adding a new
  declaration (.d.ts) file containing `declare module '@shell/plugins/i18n';`
      1 | import { Store } from 'vuex';
      2 |
    > 3 | import { stringFor } from '@shell/plugins/i18n';
        |                           ^^^^^^^^^^^^^^^^^^^^^
      4 |
      5 | let store: Store<any> | null = null;
      6 | /**

This issue appears to be isolated to Kubewarden, but the root cause can be linked to kubewarden depending on later versions of typescript than shell and other extensions, so this failure could be linked to better type checking overall.

There's also a risk that we will encounter these issues for other extensions in the future as we update dependencies in shell.

After updating the types for the i18n plugin, we received a new typescript warning:

ERROR in node_modules/@rancher/shell/composables/useI18n.ts:14:20
  TS2345: Argument of type 'Store<any> | null' is not assignable to parameter of type
  'Store<any>'.
    Type 'null' is not assignable to type 'Store<any>'.
      12 |  */
      13 | const t = (key: string, args?: unknown, raw?: boolean): string => {
    > 14 |   return stringFor(store, key, args, raw);
         |                    ^^^^^
      15 | };
      16 |
      17 | export type I18n = { t: typeof t };

I added some guards to ensure that the store is available before invoking stringFor().

Areas or cases that should be tested

Publish an updated versions of shell to a local registry or link the package. Kubewarden should no longer show type errors.

We will want to test with a few other extensions, but that should be covered by CI.

Areas which could experience regressions

This adds better type support for the i18n plugin. Other extensions might rely on ill defined types and will need to updated accordingly to support the change.

Screenshot/Video

NA

Checklist

  • The PR is linked to an issue and the linked issue has a Milestone, or no issue is needed
  • The PR has a Milestone
  • The PR template has been filled out
  • The PR has been self reviewed
  • The PR has a reviewer assigned
  • The PR has automated tests or clear instructions for manual tests and the linked issue has appropriate QA labels, or tests are not needed
  • The PR has reviewed with UX and tested in light and dark mode, or there are no UX changes
  • The PR has been reviewed in terms of Accessibility
  • The PR has considered, and if applicable tested with, the three Global Roles Admin, Standard User and User Base

@cnotv
Copy link
Member

cnotv commented Dec 10, 2025

We need to bind the use of dependencies better here.
I predicted this issue to happen back in May, looks like it took longer than expected to happen 😄
rancher/kubewarden-ui#1186

Copy link
Member

@cnotv cnotv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely sure why do we need a script to define a .d.ts, but I guess it's ok given the existing pattern.

Could we take the change to bump the version? If you want to do not mixup stuff it's also ok another PR.

Note: that composable needs a test.

@rak-phillip rak-phillip merged commit d594034 into rancher:master Dec 10, 2025
85 of 94 checks passed
@rak-phillip rak-phillip deleted the task/export-i18n-types branch December 10, 2025 22:02
@cnotv
Copy link
Member

cnotv commented Dec 12, 2025

Can confirm issue solved, thanks 🥂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants