1.0.4
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.
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'.
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...
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 :)