Seth
Seth

Reputation: 6832

How to avoid "unresolved function" error with TypeScript mixins?

WebStorm is reporting an unresolved function when I use Durandal's Events.includeIn() mixin method on a TypeScript class:

class Foo {
  bar() {
    ...
    this.trigger('myEvent', payload);  // trigger is unresolved function
    ...
  }
}

Events.includeIn(Foo);

Is there a way to resolve this without using WebStorm to suppress each unresolved call?

Upvotes: 3

Views: 861

Answers (1)

Nathan Friend
Nathan Friend

Reputation: 12814

In order to call the trigger method on the Foo class, you will need to inform the TypeScript compiler about the trigger method. You can do this by declaring the methods that will exist after the includeIn call in the class definition:

class Foo {

  // I'm not sure of the exact parameter/return types
  trigger: (eventName: string, payload: any) => void;

  bar() {
    ...
    this.trigger('myEvent', payload);  // now this function exists
    ...
  }
}

Events.includeIn(Foo);

Upvotes: 1

Related Questions