Pnpjs: Typescript def for 'sp' config in @pnp/common 'setup' function is not available

Created on 26 Apr 2018  路  3Comments  路  Source: pnp/pnpjs

Category

  • [x] Bug

Version

1.0.4

Expected / Desired Behavior / Question

As per this guide: https://github.com/SharePoint/PnP-JS-Core/wiki/Moving-from-2.0.-to-3.0.

I should be able to migrate my 'sp' settings object to setup({sp:myObject}), but the sp type is absent.

Observed Behavior

The sp type does not work, but if I cast the setup function as any it works fine.

Error:

Argument of type '{ sp: { headers: { "Accept": string; }; }; }' is not assignable to parameter of type 'LibraryConfiguration'. Object literal may only specify known properties, and 'sp' does not exist in type 'LibraryConfiguration'.

Steps to Reproduce

This doesn't work:

import {setup} from "@pnp/common";
setup({sp:{headers:{"Accept":"application/json;odata=verbose"}}});

This does actually work:

import {setup} from "@pnp/common";
(setup as any)({sp:{headers:{"Accept":"application/json;odata=verbose"}}});

Also I'm a bit confused about how this is doing setup: https://github.com/pnp/pnpjs/blob/dev/packages/sp-addinhelpers/docs/index.md

Doesn't seem to be doing it the same way as @pnp/sp. Is this fully baked? I could log another ticket for this...

code answered question

All 3 comments

Hi @alirobe,

Any specific reason to import setup from @pnp/common but not from @pnp/sp?

import { sp } from "@pnp/sp";

sp.setup({
  sp: {
    headers: {
      "Accept": "application/json;odata=verbose"
    }
  }
});

There are different setup methods in play here. There is a core setup method in common that handles any shared configuration. What you want is the setup method from the @pnp/sp library. That includes the type you expect. @koltyakov 's example above is correct. The sp.setup is an extension of the setup method from common. It works because ultimately the configuration ends up in the same object behind the scenes, you are just lacking the typing.

Docs page shows the use of the sp specific configuration.

OK, I think I read some incorrect guidance somewhere - but I can't remember where, so I think I'll just close this. Fix works. Thanks for the answer :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drewcook picture drewcook  路  3Comments

BrianBusby picture BrianBusby  路  3Comments

simonagren picture simonagren  路  3Comments

KieranDaviesV picture KieranDaviesV  路  3Comments

jcosta33 picture jcosta33  路  3Comments