I am using PnP JS in SPFx to get page content. I wanted to get content type id of the page and check if it belongs to certain content type.
I can't seem to make contain or includes function work so I have been trying to use substring to get first 44 character out so I can use it to compare but I am getting error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'substring')
import { sp } from "@pnp/sp/presets/all";
public onInit(): Promise<void> {
sp.setup({
spfxContext: this.context
});
sp.web.lists.getById(this.context.pageContext.list.id.toString())
.items.getById(this.context.pageContext.listItem.id)
.select("ContentTypeId")
.get()
.then(d=>{
console.log(d);
let content:string=d.contentTypeId
let sitecontentid:string= "0x01100912345D1CB255DA76424F860D91F20E6C4118000B8757F9909754BBB035517811AE70E"
let contentid:string= content.substring(0,43)
if (contentid==sitecontent)
{
do something
}
})
return Promise.resolve();
}
}