I have the following type script inside my ReactJs SPFx sharepoint online web part:-
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
IPropertyPaneConfiguration,
IPropertyPaneDropdownOption,
PropertyPaneDropdown} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import * as strings from 'ContactListWebPartStrings';
import ContactListApp from './components/ContactListApp';
import { IContactListProps } from './components/IContactListProps';
import { sp } from "@pnp/sp/presets/all";
export interface IContactListWebPartProps {
department: string;
}
export default class ContactListWebPart extends BaseClientSideWebPart<IContactListWebPartProps> {
private viewModeOptions: IPropertyPaneDropdownOption[] = null;
public render(): void {
const element: React.ReactElement<IContactListProps> = React.createElement(
ContactListApp,
{
department: this.properties.department,
context: this.context
}
);
ReactDom.render(element, this.domElement);
}
protected onDispose(): void {
ReactDom.unmountComponentAtNode(this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
public onInit(): Promise<void> {
return super.onInit().then( _ => {
sp.setup({
spfxContext: this.context
});
const choice =
sp.web.lists.getByTitle('Contacts').fields.getByTitle('Department').get();
this.viewModeOptions = choice.Choices.map((choice: string, idx: number) =>
{
return {
key: idx,
text: choice
}
})
});
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneDropdown('department', {
label: 'Department',
options: this.viewModeOptions,
selectedKey: this.viewModeOptions[0].key,
disabled: !this.viewModeOptions
}),
]
}
]
}
]
};
}
}
but i am getting this error on choice.Choices.map:-
Property ‘Choices’ does not exist on type ‘Promise’
here is my web part details:-
{
"@microsoft/generator-sharepoint": {
"isCreatingSolution": true,
"environment": "spo",
"version": "1.12.1",
"libraryName": "contact-list-webpart",
"libraryId": "aa3dbbd0-0d6b-4cae-98b0-c29c37998c6e",
"packageManager": "npm",
"isDomainIsolated": false,
"componentType": "webpart"
}
}