This is a migrated thread and some comments may be shown as answers.

Argument of type 'null' is not assignable to parameter of type 'GridDataResult'

3 Answers 3439 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jayaram Krishnan
Top achievements
Rank 1
Jayaram Krishnan asked on 12 Nov 2017, 06:48 AM

Hi,

I am trying to replicate the sample at https://www.telerik.com/kendo-angular-ui/components/grid/data-operations/data-binding/.I am getting the following error highlighted on my VS2017 and during run time:

Argument of type 'null' is not assignable to parameter of type 'GridDataResult'.

the error is occurring because of this code:

export abstract class NorthwindService extends BehaviorSubject<GridDataResult> {
 
    constructor(
        private http: HttpClient,
        protected tableName: string
    ) {
        super(null);//this line is causing 'Argument of type 'null' is not assignable to parameter of type 'GridDataResult'
    }

 

Thanks

Madani

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Topalov
Telerik team
answered on 15 Nov 2017, 06:44 AM
Hi Madani,

This is a TypeScript error that can be easily fixed by passing an object of type GridDataResult (one containing data and total properties) to satisfy the type checking, e.g.:

...
const emptyDataResult = {
  data: [],
  total: 0
}
 
super(emptyDataResult);

http://plnkr.co/edit/Ng27Jc7Hf0rHHADv17Qu?p=preview

Alternatively you can use type casting to cast the argument to the expected GridDataResult type.

I hope this helps.

Regards,
Dimiter Topalov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ruchika
Top achievements
Rank 1
answered on 25 Jan 2018, 10:01 PM

I am trying to use the example from 

http://plnkr.co/edit/Ng27Jc7Hf0rHHADv17Qu?p=preview

 

protected fetch(tableName: string, state: any): Observable<GridDataResult> {
        const queryStr = `${toODataString(state)}&$count=true`;
        return this.http
            .get(`${this.BASE_URL}${tableName}?${queryStr}`)
            .map(response => (<GridDataResult>{
                data: response['value'],
                total: parseInt(response["@odata.count"], 10)
            }));
    }

 

getting error at 

               data: response['value'],
                total: parseInt(response["@odata.count"], 10)

Error TS7017 (TS) Element implicitly has an 'any' type because type 'Response' has no index signature.

 

0
Dimiter Topalov
Telerik team
answered on 29 Jan 2018, 12:40 PM
Hi Ruchika,

This is a typical TypeScript error, thrown when indexing property access syntax is attempted on an object that does not have an index signature:

https://stackoverflow.com/questions/32968332/how-do-i-prevent-the-error-index-signature-of-object-type-implicitly-has-an-an

In the discussed example, this type of accessing the response's fields is imposed by the specifics of the OData protocol. You can resolve it either by disabling the "noImplicitAny" TypeScript flag, or providing the verbose signature as described in the StackOverflow thread, linked above.

I hope this helps.

Regards,
Dimiter Topalov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Jayaram Krishnan
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Ruchika
Top achievements
Rank 1
Share this question
or