1

My WebPart makes use of Redux. My dataAction calls a Service (ServiceScope) to fetch data. Because my Service uses HTTPClient I send the WebPartContext as Parameter from WebPart to Action.

The dataAction:

export function getRecentChanges(filter: IFilter, context: WebPartContext) {  
  return (dispatch) => {
    var dataService: IRecentChanges<Array<IData>> = null;
    const serviceScope: ServiceScope = context.serviceScope.getParent();
      serviceScope.whenFinished((): void => {
         dataService = serviceScope.consume(RecentChanges.serviceKey as any) as IRecentChanges<Array<IData>>;
        var p1 = dataService.getRecentChanges(context, "", "");
        p1.then(data => {
          dispatch(loadRecentChangesSuccess(data));
          dispatch(dataLoadingCompleted());
        }).catch((reason: any) => {
          dispatch(resetErrorMessage());
      });
      });
  };
}

My WebPart will call the Redux-Action like so:

export default class RecentChangesWebPart extends BaseClientSideWebPart<IRecentChangesWebPartProps> {

  protected onInit(): Promise<void> {
    var self = this;
    store.dispatch((dispatch) => {
      dispatch(getRecentChanges(null,self.context));
    });
    return super.onInit();
  }
....

When I run gulp bündle, Visual Studio Code complaints about the WebPart-Context.

Error - typescript - src/webparts/recentChanges/actions/dataActions.ts(42,46): error TS2345: Argument of type 'WebPartContext' is not assignable to parameter of type 'WebPartContext'.

Line and column from this message is pointing to:

dataService = serviceScope.consume(RecentChanges.serviceKey as any) as IRecentChanges<Array<IData>>;

Column 46 is the first e of RecentChanges.

Version from WebPart package.json:

"@microsoft/sp-core-library": "~1.4.1",
"@microsoft/sp-lodash-subset": "~1.4.1",
"@microsoft/sp-webpart-base": "~1.4.1",
"@types/react": "15.6.6",
"@types/react-dom": "15.5.6",
"@types/webpack-env": ">=1.12.1 <1.14.0",
"office-ui-fabric-react": "^5.55.3",
"react": "15.6.2",
"react-dom": "15.6.2"

So, What could cause the message "Argument of type 'WebPartContext' is not assignable to parameter of type 'WebPartContext'."

1

Issue resolved.

I used the terminal of visual studio code to get the versions of npm and node by calling: node -v and npm -v

I realized that my versions are may too old and updated node and npm to the latest versions and the error was gone.

Hope this helps others, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.