getpropertypaneconfiguration
1 TopicWebpart list property using PNPJS
I am writing a simple web part. It takes a property of "List". The user will pick the list from a dropdown. I am using the tutorial found here: https://www.sharepointnutsandbolts.com/2016/09/sharepoint-framework-spfx-web-part-properties-dynamic-dropdown.html I have the following function that uses PNPJS to return an array of the lists on the site. protected fetchLists(): Array<IPropertyPaneDropdownOption> { let options: Array<IPropertyPaneDropdownOption> = new Array<IPropertyPaneDropdownOption>(); sp.web.lists.select('ID', 'Title', 'DefaultViewUrl').get().then(function(data) { for (let i = 0; i < data.length; i++) { if (data[i].DefaultViewUrl.includes('/Lists/')) { options.push({ key: data[i].Title, text: data[i].Title, }); } }) console.log(options); }); return options; } The above function is called in the getPropertyPaneConfiguration with the line: let lists: Array<IPropertyPaneDropdownOption> = this.fetchLists(); protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration { let lists: Array<IPropertyPaneDropdownOption> = this.fetchLists(); return { pages: [ { header: { description: this.description }, groups: [ { groupName: 'Properties', groupFields: [ PropertyPaneDropdown('list', { label: 'List', options: lists }), PropertyPaneTextField('field', { label: 'Field' }) ] } ] } ] } } The problem is the sp.web.lists... call is seen by the editor as not ways returning a value. I have tried to use the .then(function() {}) to return the array but the IDE still says not all paths return a value. How can I satisfy the IDE and still always get a return array (even if it is empty)?2.3KViews0likes4Comments