fix(plugin-e2e): type window.grafanaBootData as @grafana/data's BootData - #2812
fix(plugin-e2e): type window.grafanaBootData as @grafana/data's BootData#2812unlikelyzero wants to merge 1 commit into
Conversation
The global Window.grafanaBootData augmentation previously declared an inline shape that was only a subset of Grafana core's real BootData type. When a TypeScript program pulls in both this package's ambient declaration and Grafana's own (e.g. an app's tsconfig that includes both app source and this package), the merged interface property types are not identical, which is a hard TS2717 error normally masked only by skipLibCheck. Depending on file processing order, whichever declaration is checked first silently wins. Typing grafanaBootData as @grafana/data's BootData directly removes the mismatch at the source.
|
|
1 similar comment
|
|
|
Thanks for the detailed issue and for raising the PR. I'd rather not take Looking closer at this, window.grafanaBootData augmentation in plugin-e2e is actually only needed internally by one fixture, it's not part of the real public API. So instead of widening it to match |
What this does
Types the global
Window.grafanaBootDataambient augmentation inplugin-e2easimport('@grafana/data').BootDatainstead of a hand-rolled inline subset.Fixes: #2811
Why
The previous inline shape was a strict subset of Grafana core's real
BootDatatype. When asingle
tscprogram merges this package's ambientWindowdeclaration with Grafana's own(e.g. Grafana core's tsconfig for typechecking
e2e-playwrightalongside app source), themerged property types must be identical or TypeScript raises TS2717. Grafana core currently
masks this via
skipLibCheck: trueand works around the resulting file-order sensitivity withan explicit
includearray ordering (see grafana/grafanae2e-playwright/tsconfig.json) — afragile mechanism, since which declaration silently wins depends on unspecified compiler
behavior.
Using Grafana's own
BootDatatype directly removes the structural mismatch at the source, sodownstream consumers no longer need to work around merge order.
Changes
packages/plugin-e2e/src/index.ts:grafanaBootDatais now typed asimport('@grafana/data').BootData.packages/plugin-e2e/package.json: adds@grafana/dataas adependenciesentry (it was notpreviously a dependency of this package).
Verification
npm run typecheck -w @grafana/plugin-e2e,npm run build -w @grafana/plugin-e2e,npm run lint -w @grafana/plugin-e2e, andnpm run test -w @grafana/plugin-e2eall pass.file:dependency in agrafana/grafanacheckout. With the fix installed, reversing the
includearray order ine2e-playwright/tsconfig.json(which previously reproduced 3 TS2717-driven errors inpackages/grafana-runtime/src/config.tsandpackages/grafana-ui/src/components/DateTimePickers/WeekStartPicker.tsx) no longer reproducesthose errors. With the normal include order,
typecheck:e2estays clean.Note for reviewers
Raised the approach in #2811 first since this changes the package's public ambient type surface
and adds a new dependency (
@grafana/data) thatplugin-e2edid not previously have. Open toan alternative shape if maintainers prefer not to take that dependency (e.g. dropping
grafanaBootDatafrom the global augmentation entirely and keeping it as a package-local type).