Question

When I try to create array, to put the results in the array, then I get the following error message:

const allItems : any [] = sp.web.lists.getByTitle("Documents").items.get();

Type 'Promise<any[]>' is missing the following properties from type 'any[]': length, pop, push, concat, and 16 more.ts(2740)

What am I doing wrong?

Was it helpful?

Solution

Seems you are missing await in your code. Try using below code:

import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";

// get all the items from a list
const items: any[] = await sp.web.lists.getByTitle("Documents").items.get();
console.log(items);

Reference: List Items - Basic Get

OTHER TIPS

Just add await in your code, use this instead:

const allItems : any [] = await sp.web.lists.getByTitle("Documents").items.get();
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top