I use PnP in an SPFx web part. I'm wondering is it possible to know if its a Document Library or a List that's being access in getByTitle?

var colsToSelect = [


//const data: ITab[] = [];
let web = Web(this.props.webURL);
const items: any[] = await web.lists.getByTitle("ListOfLinks").items.select(...colsToSelect).get();
  • Hi Pete, what exactly is your requirement? What you want to do with the information whether its library or list? Oct 20 '21 at 8:23
  • Hi @GaneshSanap if it's a DL I want to select the FileRef column and then display the link to the file. If it's not I don;t want to select that column. Is there a way to select all the columns in the list / DL? Thanks for the help. P Oct 20 '21 at 8:29

You cannot get the type of list while using lists.getByTitle("<name>").items endpoint.

You can identify the type of list based on it's BaseTemplate like below:

let colsToSelect: string[] = [];

const r = await sp.web.lists

if (r.BaseTemplate === 101) {
  console.log("It's a document library");
} else {
  console.log("It's a list");

You can find other BaseTemplate enum values at: ListTemplateType enumeration

  • Please Upvote(^) and accept as an Answer if my reply helped you in any way & it will help others with similar question in future to find the correct answer easily. Oct 21 '21 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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