I want to get a sharepoint list and assign it to my list 'items' which of type is IExampleItem, but I don't really know how to do it; I tried the following code but it gives me an error, my list 'items' is not compatible with what my
closed as unclear what you're asking by Robert Lindgren, Ganesh Sanap, Gaurravs, Asad Refai, Hardik Sep 9 at 9:40
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
_getFacItems return Promise《T》 so it not same as IExampleItem.
I did sample test demo in my github project below, I bind data in component not in webpart directly, while it might be helpful for you.
Check the type of 'items' in the FAQ component.
It must match with the return type of
While there is nothing technically wrong with loading the items in the FaqWebPart, I prefer to load it in the component for performance reasons. That way, it appears that the web part is faster (even if it isn't, really) by first rendering an empty list, and rendering a filled list once the items are loaded. You can even be fancy and add a 'loading' message, a spinner, or a shimmer to your list.
The trick to solve the error you get is to map the returned list items (which are of type
any when they get returned) to a
IExampleItem in your original code). In this example, assigned the returned items to a
const variable to make it easier to read the code.
Here is how I would change the code to do this:
Full disclaimer: I did not build or run this code. There may be errors, but I should demonstrate the concept.
I hope this helps?