Types & the dw API

Bundled SFCC API types, typed CommonJS modules, JSDoc, generic collections, and types generated from metadata, forms, and hooks.json

The scripting engine uses TypeScript's language service for JavaScript, TypeScript, and Digital Script. Bundled SFCC declarations describe the platform APIs; indexed modules and generated declarations describe your project. Those types power completion, hover, signatures, diagnostics, and navigation

Bundled SFCC API types

Hovering getOrder shows the method declaration and its API documentation as Markdown; links point at the referenced types and the @param, @returns, @see and @throws tags follow
cartridge/scripts/helpers/productName.js
var ProductMgr = require('dw/catalog/ProductMgr');

function getProductName(id) {
    var product = ProductMgr.getProduct(id);
    return product ? product.name : '';
}

module.exports = { getProductName: getProductName };

Invoke completion on ProductMgr or on the returned product. Hover a member for its declaration and documentation; use Go to Definition to inspect the bundled API type. No separate @types installation is needed for this editing workflow

The declarations describe the API version bundled with the extension. They do not discover a sandbox's runtime API dynamically

Give your own code useful types

/**
 * Build a readable label for a product.
 * @param {dw.catalog.Product} product
 * @returns {string}
 */
function getLabel(product) {
    return product.name || product.ID;
}

module.exports = { getLabel: getLabel };

JSDoc supplies parameter types and documentation without converting the file. The server also completes dw.* names inside JSDoc type expressions

function getLabel(product: dw.catalog.Product): string {
    return product.name || product.ID;
}

module.exports = { getLabel };

Explicit types and ordinary TypeScript inference use the same SFCC API model. See TypeScript for deployment and debugging

Importing the helper through a resolved require() carries its exported signature to the caller. A variable or property that remains any cannot supply the same member checks; annotations help when the engine cannot infer a meaningful type

Collection element types

Generic declarations can preserve the element type of SFCC collections and their callbacks. The extension also provides a typed overlay for the SFRA cartridge/scripts/util/collections helper when its bundled declaration is available

var collections = require('*/cartridge/scripts/util/collections');

/** @param {dw.util.Collection<dw.catalog.Product>} products */
function getProductIds(products) {
    return collections.map(products, function (product) {
        return product.ID;
    });
}

The aim is to keep product connected to the collection's element type inside the callback. A custom replacement of the helper must still have a compatible runtime API; a declaration overlay does not alter the implementation

Types generated from your project

Keep editing and runtime behavior aligned

The engine can model require, module.superModule, Digital Script imports, and embedded ISML expressions without executing them. Type-aware editing does not install runtime globals, polyfill JavaScript APIs, or change how SFCC loads a module

Use Module resolution for cartridge paths, Imports & the Rhino engine for runtime constraints, and Diagnostics for current checking and editing limits

On this page