TypeScript types
The Quomerce script is not on npm yet. To get types for window.qm in a TypeScript project (Next.js, Vite, Nuxt…), copy one file into your project.
Download the file
Section titled “Download the file”curl -o types/qm.d.ts https://docs.quomerce.com/sdk/qm.d.tsThe same file is served next to the script, at https://ingest-prod.quomerce.com/sdk/v0/qm.d.ts. You can also open it in the browser.
Make sure your tsconfig.json includes the file. Next.js projects include every .ts file by default ("include": ["**/*.ts", "**/*.tsx", …]), so there is nothing to do.
What you get
Section titled “What you get”window.qmand the globalqmare typed asQmApi | undefined. They areundefinedon the server, so?.keeps server rendering safe.- Every command is checked:
"init","page","track","identify","consent"and each"commerce.*"call, with its arguments. - The data shapes can be imported:
Product,Cart,CartItem,Order,ItemList,Promotion,InitOptions,ConsentChoice,PageType.
import type { Product } from "./types/qm";
const product: Product = { id: "gpu-1", name: "RTX 4070", price: 2899.99, currency: "PLN" };
window.qm?.("commerce.cartAdded", product, 1); // ✓window.qm?.("commerce.cartAddd", product, 1); // ✗ not a commandwindow.qm?.("commerce.productViewed", { id: 1 }); // ✗ a product needs a name, price and currencywindow.qm?.("page", { type: "landing" }); // ✗ not a page typeKeeping it up to date
Section titled “Keeping it up to date”The script under /sdk/v0/ only gets compatible changes, so an older copy of the file keeps working. Download it again when you want types for new calls. New calls are listed in the docs.
If your project already declares window.qm itself (for example interface Window { qm?: … }), remove that declaration. Two different types for one property are a TypeScript error.