DevExpress/devextreme-angular

Cant create data source using version 21.2.4 - breaking change

slubowsky opened this issue · 5 comments

DataSource creation that works as expected in 21.2.3 and lower no longer compiles in 21.2.4.
Using the code shown in documentation as example to create a data source - https://js.devexpress.com/Documentation/ApiReference/Data_Layer/DataSource/

new DataSource({
            load: (loadOptions) => {
                // Loading data objects
            },
            byKey: (key) => {
                // Retrieving a data object by key
            }
        });

Get typescript complier error:

[0m:38 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ load: (loadOptions: LoadOptions<any>) => void; byKey: (key: any) => void; }' is not assignable to parameter of type 'string'.

316     this.dataSource = new DataSource({
                                         ~
317       load: (loadOptions) => {
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
322       }
    ~~~~~~~
323     });
    ~~~~~

  node_modules/devextreme/data/data_source.d.ts:132:5
    132     constructor(url: string);
            ~~~~~~~~~~~~~~~~~~~~~~~~~
    The last overload is declared here.

You encountered this issue because the Typescript compiler couldn't find the expected constructor overload. You can examine available constructors by going to the DataSource declaration. You can find it by calling the Go To Definition command (usually, it is bound to the F12 key) or by opening the node_modules/devextreme/data/data_source.d.ts file.

In your case, the basic DataSource initialization code may look as follows:

new DataSource({
  load: (loadOptions) => {
    return new Promise((r) => r([1,2,3]));
  },
  byKey: (key) => {
    return new Promise((r)=>r(1));
  }
})

Problem is that the real code already does return a promise, and works as expected in 21.2.3. Ill take another look though..

@slubowsky Could you provide a sample app or an actual code snippet from your application? It will help us investigate the problem.

@alexserov Maybe something like this? compiles in 21.2.3 - but not 21.2.4

this.dataSource = new DataSource({
      load: _loadOptions => {
        return lastValueFrom(this.httpClient.post('https://somewhere', {}))
          .then((result: any) => {
            return {
              data: result
            };
          }).catch(e => {
            console.error(e);
          });
      }
    });

@alexserov looks like removing the catch solves the problem...