Promise is missing properties
-
20-02-2021 - |
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?
La 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
Autres conseils
Just add await
in your code, use this instead:
const allItems : any [] = await sp.web.lists.getByTitle("Documents").items.get();
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange