pnp / pnp/sp-dev-fx-controls-react

ServiceScope' is not assignable

Open
#1,240 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs: Attention :wave:
Dominant language
TypeScript
Stars
433
Forks
418
Avg merge
5d 6m
Merged PRs (30d)
19

Description

Category

[ ] Enhancement

[x] Bug

[ ] Question

Version

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

Expected / Desired Behavior / Question

Building SPFx project should be successful.

Observed Behavior

Error when building SPFx project:

Argument of type 'import("[Path To Project]/node_modules/@microsoft/sp-page-context/node_modules/@microsoft/sp-core-library/dist/index-internal").ServiceKey<import("[Path To Project]/node_modules/@microsoft/sp-page-context/dist/index-internal").PageContext>' is not assignable to parameter of type 'import("[Path To Project]/node_modules/@microsoft/sp-core-library/dist/index-internal").ServiceKey<import("[Path To Project]/node_modules/@microsoft/sp-page-context/dist/index-internal").PageContext>'.
Types of property 'defaultCreator' are incompatible.
Type 'import("[Path To Project]/node_modules/@microsoft/sp-page-context/node_modules/@microsoft/sp-core-library/dist/index-internal").ServiceCreator<import("[Path To Project]/node_modules/@microsoft/sp-page-context/dist/index-internal").PageContext>' is not assignable to type 'import("[Path To Project]/node_modules/@microsoft/sp-core-library/dist/index-internal").ServiceCreator<import("[Path To Project]/node_modules/@microsoft/sp-page-context/dist/index-internal").PageContext>'.
Types of parameters 'serviceScope' and 'serviceScope' are incompatible.
Type 'import("[Path To Project]/node_modules/@microsoft/sp-core-library/dist/index-internal").ServiceScope' is not assignable to type 'import("[Path To Project]/node_modules/@microsoft/sp-page-context/node_modules/@microsoft/sp-core-library/dist/index-internal").ServiceScope'.
Types have separate declarations of a private property '_registrations'

Steps to Reproduce

Build an SPFx project with version 1.13.1, office-ui-fabric-react 7.174.1 and pnp/spfx-controls-react 3.8.0.
Add a service class with the following code:

import { ServiceKey, ServiceScope } from "@microsoft/sp-core-library";
import { PageContext } from "@microsoft/sp-page-context";

export interface IMyService {
    getSomething():Promise<string>;
}

export class MyService {

    public static readonly serviceKey: ServiceKey<IMyService> = ServiceKey.create<IMyService>('HelloWorld:MyService', MyService);

    constructor(serviceScope: ServiceScope) {        
        serviceScope.whenFinished(() => {
            const pageContext = serviceScope.consume(PageContext.serviceKey);                                          
        });                
    }

    public async getSomething() : Promise<string>{
        return "";
    }
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the SPFx build using version 1.13.1 with office-ui-fabric-react 7.174.1 and pnp/spfx-controls-react 3.8.0, then inspect the dependency tree for duplicate @microsoft/sp-core-library declarations. Confirm the fix by rebuilding the sample service that consumes PageContext.serviceKey without the ServiceScope type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.