Skip to content

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.

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

The 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.

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

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.