pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
762 stars 304 forks source link

Provide an enum for List template type, equivalent to C# SPListTemplateType #1302

Closed thw0rted closed 4 years ago

thw0rted commented 4 years ago

Category

Version

Please specify what version of the library you are using: 2.0.6

Please specify what version(s) of SharePoint you are targeting: N/A

Expected / Desired Behavior / Question

There are dozens of list template types that are represented by opaque integer codes. The docs about adding Lists use a hard coded number literal (101) instead of an enum to specify the list type. Library users should not be hard coding a magic number to represent a lookup like this. Instead, and enum should be created similar to e.g. FieldTypes that explicitly assigns a human-readable name for each number.

patrick-rodgers commented 4 years ago

There is an issue with big enums in TypeScript - when they are transpiled they create a HUGE block of static code that can't be minimized. To me there isn't much value in having a giant block of code when consumers can just use a number. We could declare the enum as const, but that would make it much less usable to consumers of the library. An example of this is that way long ago we had an enum for all the languages, I think it added like 7k to the final package.

You've linked to the list of codes so they are easy to find which suggests they aren't opaque. We can add a link in the docs for that but I am not convinced of the value of including the enum.

thw0rted commented 4 years ago

I just started using this library last week so I don't have a lot of experience, but it looked to me like you've recently refactored to support selective / tree-shake-able imports. Would it make sense to provide this enum in a way that it only winds up in your build when explicitly imported?

I made the issue because I was hoping to present the user with a "filter list catalog by base template type" dialog. I wanted to avoid hand-jamming the codes myself, and I certainly don't want to tell the user to go and look up the docs online to know that they should pick "type 109" when they want Pictures, or whatever.

github-actions[bot] commented 3 years ago

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.