1
votes

I'm using pnpjs v 2.0.0 with SPFX to achieve some list operations.

public async getitem(listname) {
    // get a specific item by id
    const item: any = await sp.web.lists.getByTitle(listname).items.getById(20).get();
    console.log(item);
    // await item.like();
    // get the liked by data
    const likedByData: ILikeData[] = await item.getLikedBy();
    console.log(likedByData);
    // get the liked by information
    const likedByInfo: ILikedByInformation = await item.getLikedByInformation();
    console.log(likedByInfo);
}

I get the item object but can't add a like to it, I'm getting the error :

Uncaught (in promise) TypeError: item.like is not a function

I've used the docummentation : @pnp/sp/comments and likes

1

1 Answers

0
votes

First: are you referencing and importing everything correctly? Just asking to be clear because your provided code doesn't show. Here's what's needed:

import { sp } from "@pnp/sp";
import "@pnp/sp/comments/item";
import { ILikeData, ILikedByInformation } from "@pnp/sp/comments";

But I guess you got that done correctly.

Secondly and maybe more likely the issue: if you take a close look at the documentation (the link you provied), on top of the page following is stated:

These APIs are currently in BETA and are subject to change or may not work on all tenants.

I tested the exact code from the documentation on my dev environment and this also doesn't work. So it might not work on your tenant yet.