简体   繁体   中英

TypeScript Error TS 2094/2095 property 'x' does not exist on value of type 'JQuery'

Hey I've been trying to figure this out but it seems to be really weird. I know to include the .d.ts file in the top. I recently upgraded ts from 0.831 to 0.95. Did all the necessary changes and still getting errors.

More specifically, I'm working with JQGrid and there is no typed file in the Definitely Typed repo so I created one. Here is the definition file.

    /// <reference path="..\Imports\jquery-1.8.d.ts" />

interface JQuery {
    jqGrid(options?: JQGrid.JQGrid_Options): JQuery;
    fluidGrid(options: JQGrid.FluidGrid_Options): JQuery;
}

declare module JQGrid {
    export interface JQGrid_ColModel {
        ...
    }

    export interface JQGrid_Options {
        ...
    }

    interface FluidGrid_Options {
        ...
    }
}

The '...' are just options.

I'm getting "error TS2094: The property 'jqGrid' does not exist on value of type 'JQuery'" from the line of code

$("#prospectsByReferrer").jqGrid(this.gridOptions);

and "error TS2095: Could not find symbol 'JQGrid'" from code

private gridOptions: JQGrid.JQGrid_Options;

The full code is

/// <reference path="..\..\Scripts\Base\ViewModelBase.ts" />
/// <reference path="..\..\Scripts\Imports\JQGrid.d.ts" />
module Biz.Views {
    export class ProspectsTab extends ViewModelBase{
        private gridOptions: JQGrid.JQGrid_Options;   <--error TS2095
        private _businessId: number;
        private _isInitialized: boolean = false;

        constructor () {
            this.gridOptions = {};
            $("#prospectsByReferrer").jqGrid(this.gridOptions);  <---error TS2094
        }

What I'm not getting is why TS can't see this typed when it's declared above. What am I not doing right? I've ran out of ideas that includes some typing. Thanks for your time.

By the way, I'm using Visual Studios 2012 and intellisense doesn't give me a red squiggly. It's only my console that outputs the error.

I expect this is a stupid answer but it happens to me all the time.. I'm also using VS and typescript.

Did you forget to include the JQGrid.js file in your HTML document?

The TS compiler seemed to flip out when I had special characters in my ts file. I comment code from Word and Word has weird characters that they format themselves such as ... , - , etc. Removing these 'weird' characters allowed the compilation to happen again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM