Jeremy
Jeremy

Reputation: 377

Typescript with and without defenition files on the same namespace

I am running into a problem when using classes that have deninitions (base.d.ts) and some that do not and are just Typescript classes (EventDispatcher.ts) with the same namespace.

All in all i'm stuck between these errors as the following is not valid syntax:

declare var Acme.Ajax: AcmeAjaxInterface;

What i am trying to do:

My base.d.ts file contains:

interface AcmeInterface{
    Ajax: AcmeAjaxInterface;
}

interface AcmeAjaxInterface{
    call(...parameters: any[]);
}

my EventDispatcher.ts contains:

module Acme {
    expost class EventDispatcher{}
}

When trying to use both in the following file:

///<reference path="base.d.ts" />
///<reference path="EventDispatcher.ts" />
Acme.Ajax.Call():

I get an error because the Acme variable is never declared:

TS2094: The property 'Ajax' does not exist on value of type 'Acme'.

However, When i add the following:

declare var Acme : AcmeInterface;

I am getting an error:

TS2000: Duplicate identifier 'Acme'.

What would be the method to prevent these errors from happening?

Upvotes: 0

Views: 440

Answers (1)

Jeffery Grajkowski
Jeffery Grajkowski

Reputation: 4061

declare var Acme.Ajax: AcmeAjaxInterface;

Should be

declare module Acme {
    export var Ajax: AcmeAjaxInterface;
}

You can't define/declare vars with .s in the name. module is how you put things in a namespace. Note that you can use .s as a shortcut to nested modules eg: declare module Alpha.Bravo.Charlie { /*...*/ }.

Upvotes: 2

Related Questions