sp-dev-fx-controls-react: Type 'WebPartContext' is not assignable to type 'BaseComponentContext'.

Category

[ ] Enhancement

[ ] Bug

[X] Question

Version

Please specify what version of the library you are using: [ 3.0.0 ]

Expected / Desired Behavior / Question

Before 3.0.0 the context={props.context} for FilePicker and ListItemPicker was OK with WebPartContext inherited from the context: this.context from the web part class.

Observed Behavior

After upgrade to 3.0.0 , TS complains that “Type ‘WebPartContext’ is not assignable to type ‘BaseComponentContext’.”

I am OK for now by using context={props.context as any} But I would like to know the right way to do it.

Thanks for a great collection!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 38 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I was getting this on the PropertyFieldColumnPicker and this worked for me to get past this error. context: this.context as any,

@pnp/spfx-controls-react”: “3.4.0”, with SPFx 1.13.0 shows the same typescript error 😃

@Ofer-Gal beta version with 1.13 support is ready 😃

I use it as any

context={Context as any}

Works

Hey dudes!

I’m getting the same error when trying to use FilePicker. PropertyFieldFilePicker("filePicker", { context: this.context, filePickerResult: this.properties.filePickerResult, onPropertyChange: this.onPropertyPaneFieldChanged.bind(this), properties: this.properties, onSave: (e: IFilePickerResult) => { console.log(e); this.properties.filePickerResult = e; }, onChanged: (e: IFilePickerResult) => { console.log(e); this.properties.filePickerResult = e; }, key: "filePickerId", buttonLabel: "File Picker", label: "File Picker", })

Error: Type 'WebPartContext' cannot be assigned to type 'BaseComponentContext'. Types have separate declarations of a private property '_serviceScope'.ts(2322) IPropertyFieldFilePicker.d.ts(114, 5): Expected type comes from property 'context', which is declared here in type 'IPropertyFieldFilePickerProps'

Dependency versions: “@microsoft/sp-build-web”: “1.16.1”, "@microsoft/sp-core-library": "1.16.1", "@microsoft/sp-property-pane": "^1.16.1", "@microsoft/sp-webpart-base": "^1.16.1", "@pnp/spfx-controls-react": "^3.13.0", "@pnp/spfx-property-controls": "^3.12.0",

Using latest beta shows the same error

Thank you @Ofer-Gal for reporting this one.

v3 is based on SPFx v1.12 and up.

For SPFx v1.11 use the latest v2 release.

@dorin2006 what Ofer-Gal suggests is a way to overcome this. The PnP Controls solution is still on 1.17.3 and you are using 1.17.4, hence the differences

@cardinalpipkin That’s exactly what I mean. And that is also the fix/workaround I used. The Problem is in spfx-controls-react. Not in Sharepoint. Maybe I should have been clearer.

Ok thanks. I’m trying the latest beta now (3.5.0-beta.1412592), but I’m still getting the same error. Should I open a new issue?

I’m getting this now with PeoplePicker, with SPFx 1.13.0 and “@pnp/spfx-controls-react”: “^3.4.1”. Using context={this.props.context as any}

gives Error - [webpack] ‘dist’: ./lib/webparts/{project}/components/{file}.js 392:137 Module parse failed: Unexpected token (392:137) File was processed with these loaders:

  • ./node_modules/source-map-loader/index.js You may need an additional loader to handle the result of these loaders.