0

I'm just a poor programmer who inherited some TypeScript code. Sometimes you just want a clue what is going on without taking a few weeks off to become fluent in a new language. I have an interface:

interface IJQuery {
    addRecordInline(object: any);
}

I'm getting an error on addRecordInline:

"Named property type '(object any) => any' must be assignable to string indexer type 'HTMLElement': Type 'HTMLElement' has non-optional property 'accessKey' which is not present in type '(object any) => any'

Just any kind of clue as to what is going on would be appreciated. I've looked around the internet ... there are some posts about Indexers that seem the closest. But what is happening here? Just a pointer to some information. Thank you.

EDIT:

Examples of the interface being implemented:

interface IDocumentManager {
    UpdateForm: IJQuery;
    UpdateActionUrl: string;
    DocIdPrefix: string;
}

2nd EDIT:

Here is a class that implements the interface:

class MemberDocumentManager implements IDocumentManager {
    private ConfirmDeleteButton: IJQuery;
    // other declarations removed

    constructor() {
        this.ConfirmDeleteButton = $('#deleteConfirmButton');
    }
}

A JQuery object is being assigned to a member that implememnts the interface in question, is that the problem?

3
  • Where are you implementing that interface? Commented Feb 22, 2018 at 18:06
  • The interface is assigned to members of other interfaces from what I can tell: "interface IDocumentManager { UpdateForm: IJQuery; } and other cases of the same. Commented Feb 22, 2018 at 18:16
  • 1
    Still too less code. The mistake is a missmatch of type and values, so we need to see the values (were you implement it) Commented Feb 22, 2018 at 18:19

1 Answer 1

1

Based on the error, that is not the only definition of IJQuery. As far as I can tell this is specific to your project and is not part of the JQuery library.

Form the error, there is probably a definition of IJQuery that contains an indexer:

interface IJQuery {
    [name: string]: HTMLElement
}

Which means all properties defined on this type must be of type HTMLElement

interface IJQuery {
    addRecordInline(object: any) : void; // Not ok
    anElement: HTMLElement // OK
}

You can either relax the restriction by removing the indexer ([name: string]: HTMLElement) or define the method on another interface or change the indexer to return either an element or a function ([name: string]: HTMLElement | Function)(although this will probably break your code in several places)

Sign up to request clarification or add additional context in comments.

3 Comments

It appears to me the definition of the interface IJQuery is colliding with declarations of the same interface that is defined in bootstratp.d.ts and jquery.d.ts and even jquery.uploadify.d.ts. When I changed the name of the interface to IJQuery2, the errors appear to be resolved. Seem like a reasonable explanation?
@Evan I did not find it in the typings for JQuery but for sure it is colliding with another definition
Titian: can you add more detail on how this interface merging can be accomplished? I can't change the original JQuery interface but how would I merge a new interface, do I have to make all new members be of type HTMLElement?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.