0

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?

2 Answers 2

1

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

1

Just add await in your code, use this instead:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.