Przejdź do głównej zawartości

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.

Terminal window
curl -o types/qm.d.ts https://docs.quomerce.com/sdk/qm.d.ts

It 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).

  • window.qm and qm are typed as QmApi | 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 command
window.qm?.("commerce.productViewed", { id: 1 }); // ✗ a product needs a name, price and currency
window.qm?.("page", { type: "landing" }); // ✗ not a page type

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.