|
| 1 | +importtype{GoogleTagManagerApi}from'../../packages/script/src/runtime/registry/google-tag-manager' |
| 2 | +import{describe,expectTypeOf,it}from'vitest' |
| 3 | + |
| 4 | +/** |
| 5 | + * Regression guard for #852. |
| 6 | + * |
| 7 | + * `@gtm-support/core` (the engine behind `@gtm-support/vue-gtm`) declares |
| 8 | + * `Window.dataLayer?: DataLayerObject[]`. Interface declarations merge, so if this package |
| 9 | + * also declares `dataLayer` on the global `Window`, the merged `Window` fails this package's |
| 10 | + * own `extends` clause. TypeScript then reports TS2430 at every one of the consumer's own |
| 11 | + * `Window` augmentations, which the consumer cannot suppress. |
| 12 | + * |
| 13 | + * `dataLayer` must stay off the global `Window`. Its name is configurable through the |
| 14 | + * `l` / `dataLayer` options anyway, so `window.dataLayer` was never guaranteed to exist. |
| 15 | + * The proxy returned by `useScriptGoogleTagManager()` is the supported access path. |
| 16 | + */ |
| 17 | +describe('global `Window` augmentation',()=>{ |
| 18 | +it('does not declare `dataLayer`',()=>{ |
| 19 | +expectTypeOf<'dataLayer'extendskeyofWindow ? true : false>().toEqualTypeOf<false>() |
| 20 | +}) |
| 21 | + |
| 22 | +it('keeps `google_tag_manager` declared',()=>{ |
| 23 | +// `useScriptGoogleTagManager`'s `use()` reads `window.google_tag_manager` directly. |
| 24 | +expectTypeOf<Window['google_tag_manager']>().toEqualTypeOf<GoogleTagManagerApi['google_tag_manager']>() |
| 25 | +}) |
| 26 | + |
| 27 | +it('still types `dataLayer` on the GTM proxy API',()=>{ |
| 28 | +expectTypeOf<GoogleTagManagerApi['dataLayer']>().not.toBeAny() |
| 29 | +expectTypeOf<GoogleTagManagerApi['dataLayer']['push']>().toBeCallableWith({event: 'test'}) |
| 30 | +}) |
| 31 | +}) |
0 commit comments