Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PeoplePicker context type mismatch with SPFx 1.16.1 #1427

Closed
DPCamino opened this issue Jan 26, 2023 · 7 comments · Fixed by #1471
Closed

PeoplePicker context type mismatch with SPFx 1.16.1 #1427

DPCamino opened this issue Jan 26, 2023 · 7 comments · Fixed by #1471
Labels
status:fixed-next-drop Issue will be fixed in upcoming release.
Milestone

Comments

@DPCamino
Copy link

Category

[ ] Enhancement

[X] Bug

[ ] Question

Version

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

Expected / Desired Behavior / Question

The desired behavior is to be able to use the context object Microsoft provides.

Observed Behavior

I am using a PeoplePicker in a Form Customizer extension.
When you try to simply use the context object you get the following error:


Type 'FormCustomizerContext' is not assignable to type 'BaseComponentContext'.
  Types have separate declarations of a private property '_serviceScope'.ts(2322)

Steps to Reproduce

With a Form Customizer extension, the context object is a different type: 'FormCustomizerContext'

Using SPFx v1.16.0, I could declare the context property as this context object without issue.
However, using SPFx v1.16.1, you cannot use the same object without getting a type mismatch error.

Even though the the type is different, I didn't experience an error using SPFx 1.16.0 or earlier.

You can eliminate the error by casting the type as 'any', but I'm unsure if that is the correct way to solve this issue.

property={context as any}

Someone else has also experienced a similar context type mismatch with FilePicker when upgrading to 1.16.1
Issue #1426

Thank you!

@ghost
Copy link

ghost commented Jan 26, 2023

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added the Needs: Triage 🔍 label Jan 26, 2023
@salascz
Copy link

salascz commented Jan 30, 2023

Hello,
I would like to ask similar question - Is it possible to use latest SPFx controls react (3.12.0) with SPFx 1.16.1?

I am building my project from multiple PnP components (e.g., SPFX Controls react + PnP Modern Search Extensibility). It is a pity to search for the matching version of SPFx for all components + I cannot upgrade own solution till all components got updated.

Thanks

@AJIXuMuK
Copy link
Collaborator

We will update to 1.16.1 in the next release to have proper typings.
But you still can use the library with 1.16.1 even now: you just need to cast types like as any

@AJIXuMuK AJIXuMuK added status:fixed-next-drop Issue will be fixed in upcoming release. and removed Needs: Triage 🔍 labels Jan 30, 2023
@AJIXuMuK AJIXuMuK added this to the 3.13.0 milestone Jan 30, 2023
@DPCamino
Copy link
Author

We will update to 1.16.1 in the next release to have proper typings. But you still can use the library with 1.16.1 even now: you just need to cast types like as any

Perfect! Thanks for the update 🚀

@salascz
Copy link

salascz commented Feb 1, 2023

We will update to 1.16.1 in the next release to have proper typings. But you still can use the library with 1.16.1 even now: you just need to cast types like as any

👍 Thank you for everything you and other guys do for the community.

[off-topic] (I take advantage of having @AJIXuMuK here, thanks)
I bet you know the suggestion to use as any is not a best solution. It is a very effective way, how to hide potential issues in the future - cause I will not recognise such a problem during build in case of breaking changes in the serviceScope. (Detailed changes are rarely communicated outside, so the developer might not be aware of such a thing till the error occurs during tests)

No complains, just want to point out: the situation with dependencies and upgrades might be tricky and time consuming in scenarios, where there are multiple libraries used (community & own) for a solution. (those issues usually starting with typings issues e.g. ServiceScope from @microsoft/sp-core-library :-( )

@stevebeauge
Copy link
Contributor

stevebeauge commented Feb 2, 2023

We will update to 1.16.1 in the next release to have proper typings. But you still can use the library with 1.16.1 even now: you just need to cast types like as any

Because using as any is not possible in strict mode, you can use context as unknown as IPeoplePickerProps['context'] to make typescript happy.

Something like :

                    <PeoplePicker
                        {...props}
                        defaultSelectedUsers={value}
                        context={context as unknown as IPeoplePickerProps['context']}

                    />

This way, it will compiles whatever the version of SPFX your project is.

Globally, I agree with @salascz. In large project SPFX dependencies are a pain to deal with. peerDependencies exists to deal with such situation. However, this library is build using the SPFX buildchain and this make everything more complicated. Not easy to solve I agree.

@DPCamino
Copy link
Author

DPCamino commented Mar 2, 2023

I upgraded to 3.13.0 and I'm still getting the Typescript error. Am I missing something?

I don't see any changes to the context Type in the IPeoplePicker.ts file. It's still BaseComponentContext but the form customizer context type is FormCustomizerContext

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:fixed-next-drop Issue will be fixed in upcoming release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants