TypeScript types
Ta treść nie jest jeszcze dostępna w Twoim języku.
The script is not on npm yet. To type window.qm, 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.tsIt is also at https://ingest-prod.quomerce.com/sdk/v0/qm.d.ts. Make sure your tsconfig.json includes it (Next.js does by default).
What you get
Section titled “What you get”window.qmandqmare typed asQmApi | undefined. Use?.so server rendering stays safe.- Every command and its arguments are checked.
- 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”An older copy keeps working. Download it again to get types for new calls.
If your project already declares window.qm itself, remove that declaration, or TypeScript reports an error.