sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Issue with assignable to type 'ISPLists'.

Open duncanspeidel opened this issue 7 years ago • 3 comments

#2813 ## Category

  • [ ] Question
  • [ ] Typo
  • [X ] Bug
  • [ ] Additional article idea

This is similar to the issue reported on https://github.com/SharePoint/sp-dev-docs/issues/3662 but that gives no solution and the problem is slightly different.

Working with https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/connect-to-sharepoint and the code shown does not compile. It fails with: Error - [tsc] src/webparts/helloWorld/HelloWorldWebPart.ts(83,26): error TS2345: Argument of type 'ISPLists[]' is not assignable to parameter of type 'ISPList[]'.

Error - [tsc] src/webparts/helloWorld/HelloWorldWebPart.ts(90,32): error TS2345: Argument of type 'ISPLists[]' is not assignable to parameter of type 'ISPList[]'.

Error - [tsc] src/webparts/helloWorld/HelloWorldWebPart.ts(110,13): error TS2322: Type '{ value: ISPList[]; }' is not assignable to type 'ISPLists'.

ISPList is defined as an interface:

export interface ISPLists{
  value: ISPLists[];
}

export interface ISPList{
  Title: string;
  ID: string;
}

Line 83 shows a red line under part of the statement mousing over I show: Argument of type 'ISPLists[]' is not assignable to parameter of type 'ISPList[]'. Type 'ISPLists' is missing the following properties from type 'ISPList': Title, IDts(2345). The full call is:

    if (Environment.type === EnvironmentType.Local) {
      this._getMockListData().then((response) => {
        this._renderList(response.value);
      });

Line 90 also shows a red line under response.value. The error description is: Argument of type 'ISPLists[]' is not assignable to parameter of type 'ISPList[]'.ts(2345) The code in question is:

   else if (Environment.type == EnvironmentType.SharePoint || 
        Environment.type == EnvironmentType.ClassicSharePoint) {
          this._getListData()
            .then((response) => {
              this._renderList(response.value);
      }); 

This is a continuation of the if statement shown above.

Line 110 shows a read line under value in { value: data } the long error is: Type 'ISPList[]' is not assignable to type 'ISPLists[]'. Property 'value' is missing in type 'ISPList' but required in type 'ISPLists'.ts(2322) HelloWorldWebPart.ts(32, 3): 'value' is declared here. HelloWorldWebPart.ts(32, 3): The expected type comes from property 'value' which is declared here on type 'ISPLists' The code is: private _getMockListData(): Promise { return MockHttpClient.get() .then((data: ISPList[]) => { var listData: ISPLists = { value: data }; return listData; }) as Promise; }//_getMockListData

The code can be found in: helloWorldWebPart.txt

Best regards, Duncan

duncanspeidel avatar Aug 09 '19 18:08 duncanspeidel

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

msft-github-bot avatar Aug 09 '19 18:08 msft-github-bot

I found the problem. I defined export interface ISPLists{ to have a definition of value: ISPLists[]; and it should be value: ISPList[];.

duncanspeidel avatar Aug 09 '19 18:08 duncanspeidel

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

msft-github-bot avatar Jan 23 '20 18:01 msft-github-bot