Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Global Typing

Patrick Rodgers edited this page Mar 5, 2017 · 1 revision

If you are working with a project where you are not importing the sp-pnp-js library rather using it in the global capacity you will not immediately have typings available. To address this you can add a new file, pnp-global-shim.d.ts, to your project tree with the below contents. Starting with version 2.0.2 this file will be included in the dist folder.

/// <reference path="pnp.d.ts" />
export * from "pnp";
export as namespace $pnp;

This relies on the pnp.d.ts files being in the same directory as the shim file you just created. The next step is to update your project's references to use the shim, as shown in the below sample:

/// <reference path="pnp-global-shim.d.ts" />

$pnp.Logger.subscribe(new $pnp.ConsoleListener());
$pnp.Logger.activeLogLevel = $pnp.LogLevel.Info;

$pnp.sp.web.get().then(w => {
    $pnp.Logger.write(JSON.stringify(w));
});

const web = new $pnp.Web("My Url");

web.get().then(w => {
    $pnp.Logger.write(JSON.stringify(w));
});
Clone this wiki locally