문제

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?

도움이 되었습니까?

해결책

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

다른 팁

Just add await in your code, use this instead:

const allItems : any [] = await sp.web.lists.getByTitle("Documents").items.get();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top