The 'jqGrid' property does not exist with a value of type 'jQuery'

I am using Typescript with jqGrid and jQuery.

In the next line:

jQuery(this).jqGrid('editGridRow', rowid, { ... 

I get a message:

The 'jqGrid' property does not exist for a value of type 'jQuery'.

Any ideas on how to fix this problem?

+6
source share
2 answers

I assume that you are using the jquery.TypeScript.DefinetlyTyped NuGet package.

In this case, add the file ~ / Scripts / typings / custom.d.ts with the following contents:

 /// <reference path="jquery/jquery.d.ts"/> interface JQuery { jqGrid: any; } 

Update: The above solution is generic and works in all cases. The best solution for ...

Install the jqgrid.TypeScript.DefinitelyTyped NuGet package.

+14
source

The problem is that the jQuery grid is a plugin. It looks like you have a definition file for the JQuery library, but not for the JQuery Grid plugin. I checked https://github.com/borisyankov/DefinitelyTyped and there seems to be no type definition for this particular plugin. There are a few things you could do.

  • You can assign jQuery a variable of type "any":

var localJq: any = jQuery (this); localJq.jqGrid ('editGridRow', rowid, {...});

This will deceive the compiler and allow you to access properties in var that are not defined in the definition file.

  • You can create a definition file that will add jqGrid properties to jquery. This definition file must be specified in any typescript files where you use jqGrid. Here is an example definition file for a simple jQuery plugin. As you can see, it’s easy to extend the jQuery definition with additional properties.
+3
source

Source: https://habr.com/ru/post/959496/


All Articles