I am working with several document libraries, some of them with folders (unfortunately). I develop web apps using TypeScript with REST API server interaction.
I am finding that a view configured to show Totals (counts of items for a column) is NOT matching SharePoint's own export to Excel worksheet item data counts (rows), nor my script which distinguishes folder from file items.
To illustrate, the document library has the ID and Name column both with 498 file items (17 folder items, filtered out using Content Type system column). My web app will count 490 file items. When I export the item data to Excel file from the view menu, the worksheet has 490 items (rows).
That is, the list/lib view column Total value has 8 extra items it is counting. I am not sure how to track them down or if they even exist. This is not strictly my script: I am using a SharePoint list view menu feature (export to Excel) and this result and my script agree.
The doc lib had 3 content types. One was the base type "Folder", another was a user-defined "folder" type, and other was also a user defined type intended to be used for documents as items, not folders as items. But 8 of the items of the content type intended for documents were actually folders. I'm not sure how these folders were created with this content type in the default creation of a folder/container. I will review my understanding of this.