Data version error in SPFX React -Basic Webpart

4k views Asked by At

I Just created a basic spfx webpart with react but getting bellow error:

{ "resource": "/c:/Node_Dev/CRUD_React/src/webparts/crudReact001/CrudReact001WebPart.ts", "owner": "typescript", "code": "2611", "severity": 8, "message": "'dataVersion' is defined as a property in class 'BaseClientSideWebPart', but is overridden here in 'CrudReact001WebPart' as an accessor.", "source": "ts", "startLineNumber": 35, "startColumn": 17, "endLineNumber": 35, "endColumn": 28 }

My Code:

import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
  IPropertyPaneConfiguration,
  PropertyPaneTextField
} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';

import * as strings from 'CrudReact001WebPartStrings';
import CrudReact001 from './components/CrudReact001';
import { ICrudReact001Props } from './components/ICrudReact001Props';

export interface ICrudReact001WebPartProps {
  description: string;
}

export default class CrudReact001WebPart extends BaseClientSideWebPart<ICrudReact001WebPartProps> {

  public render(): void {
    const element: React.ReactElement<ICrudReact001Props> = React.createElement(
      CrudReact001,
      {
        description: this.properties.description
      }
    );

    ReactDom.render(element, this.domElement);
  }

  protected onDispose(): void {
    ReactDom.unmountComponentAtNode(this.domElement);
  }

  protected get dataVersion(): Version {
    return Version.parse('1.0');
  }

  protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
    return {
      pages: [
        {
          header: {
            description: strings.PropertyPaneDescription
          },
          groups: [
            {
              groupName: strings.BasicGroupName,
              groupFields: [
                PropertyPaneTextField('description', {
                  label: strings.DescriptionFieldLabel
                })
              ]
            }
          ]
        }
      ]
    };
  }
}
2

There are 2 answers

1
Baker_Kong On BEST ANSWER

You can just delete 'datavaersion' method, it's compatible with SPFx v1.10 but will get an error when you install V1.11.

0
mhep On

The article linked below provides more details on the issue:

https://dreamsof.dev/2020-09-21-typescript-upgrade-breaking-dataversion-get-override-spfx11/

The suggested solutions are:

  1. Use Workspace Version for TypeScript (3.3.4000) instead of VS Code's newer version
  2. Decorate method with // @ts-ignore