Mojtaba
Mojtaba

Reputation: 1240

How should I reference a class in a definition file "*.d.ts" typescript while using external modules?

Imagine I have a class

export class Foo
{
   methodX():string
   {
   }
}

window.foo = new Foo();

and I have my window interface what is the workaround to add Foo in window interface

interface Window {
    foo:Foo;
}

this is working for internal modules but not for external modules.

Upvotes: 0

Views: 152

Answers (1)

Artem
Artem

Reputation: 1870

You cannot use ambient interfaces in internal modules, so declare interface in separate file:

interface IFoo {
    methodX(): string;
}

interface Window {
    foo: IFoo;
}

Upvotes: 1

Related Questions