-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.get() return types #199
Comments
Hey @SPWizard01, Custom data type can be provided to |
Hello, Yes I am aware of that, however I think it would be nice to have it available within pnp library. |
I've actually been thinking about this lately, what would be the best practice way to convert the response item to a TypeScript object, which might contain attributes with different names from the list columns, thus requiring a mapping of sorts from the SP List data to the TS Model? example list columns [internal names]: example TS Model attributes: |
Both topics that @SPWizard01 and @Katli95 bring up have been discussed before. I'll try and summarize the previous discussions, and welcome your thoughts.
|
Do very much want to invite a discussion here, didn't mean to close things down with my comment. |
Could you please elaborate on how the spODataEntity and parser works? I'm relatively new to this and the best method I've worked out is to manually convert the response to an interface of my own design before returning the items from a service class. |
I would assume that Interfaces for such things as list items cannot be defined because there are custom lists/custom content types etc. however those basic(or well known) ones can be done in my opinion. For me, its no big deal, there are good tools to convert response JSON into interface etc. I just think that in some cases it would help folks to get started. Maybe you are right maybe its just lack of documentation :D |
@Katli95 - you can see the article on the old repo's wiki. I have realized we didn't get it moved over for the new docs so will need to get that corrected. @SPWizard01 - as mentioned above, will certainly merge a PR if someone wants to build out those interfaces. |
I would disagree. Something like this would be helpful (building on the OP's interface): declare function select<K extends keyof IODataListResult>(...fields:K[]): Pick<IODataListResult, K>; If select is implemented like that, it errors if you try to select a non-existing property, you will get autocomplete on the select arguments, and the resulting type will be filtered down to the properties you selected. Examples: I fully support this request. |
The part of my quote above you didn't include is that I'd certainly look at merging a PR covering this. The only issue I see with this approach is that if fields are added they would effectively be hidden/blocked until the interface is updated. If you want to implement your suggestion, please do. Remember that select is shared on all the collections so we would want to ensure we are creating a solution that will work across all the objects and in a maintainable way. |
Now that I think of it, there could be another issue with expands, like |
Going to close this as inactive. As mentioned if someone wants to work at creating typings I support it, but I think it is a harder problem than it initially appears. Happy to keep the discussion going if needed, please reopen the thread. Thanks! |
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. |
Category
Version
Please specify what version of the library you are using: [1.1.4]
Expected / Desired Behavior / Question
Is there a defined set of return data types?
The following code returns
Promise<any>
:sp.web.lists.getByTitle("SomeList").get()
and i guess that's fine, however it would be nice to have a set of "defined" return types.
In my project i had to create it myself for example:
let list: IODataListResult: await sp.web.lists.getByTitle("SomeList").get()
Observed Behavior
The following code returns
Promise<any>
:sp.web.lists.getByTitle("SomeList").get()
The text was updated successfully, but these errors were encountered: