0

Models/Objects/A.ts

module App.Models.Objects
{
    export class A
    {}
}

Models/Abstracts/ISomethingElse.ts

module App.Models.Abstracts
{
    export interface ISomethingElse
    {
        A: A;
    }
}

How do i use the module App.Models.Objects from the ISomethingElse.ts file?

I have tried referencing:

/// <reference path="../Objects/A.ts" />

But it still cannot find A because it's in the module. How do i import it?

I have tried importing:

/// <reference path="../Objects/A.ts" />
import A = require("App.Models.Objects");

But it still doesn't compile.

What am i doing wrong?

Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233
  • 1
    As module names are different, in ISomethingElse you should refer A by its complete name: "App.Models.Objects.A" I think this is the only problem... – DaniCE Jul 29 '15 at 15:10

1 Answers1

0

Assuming you're not using an editor that takes care of the references for you, the relative reference path you've used is wrong. The following should work:

/// <reference path="../objects/A.ts"/>
    
module App.Models.Abstracts
{
  export interface ISomethingElse
  {
    a: App.Models.Objects.A;
  }
}
Vadim Macagon
  • 14,463
  • 2
  • 52
  • 45
  • I'm more interested in the import part so that i can alias that big module name. Can you not import the module rather than reference as you've put? like a using in c#, or an import in java, or a use in php? – Jimmyt1988 Jul 29 '15 at 10:49
  • You're using internal modules here (which I believe are now at long last correctly called namespaces), you can't require a namespace as it not a real JS module (in the CommonJS, AMD, ES6 etc. sense). If you want to use require or ES6 import with your module you need to have a top level export in your .ts file. – Vadim Macagon Jul 29 '15 at 11:01
  • You can use a type alias if all you want to do is shorten the type name. e.g. type A = App.Models.Objects.A – Vadim Macagon Jul 29 '15 at 11:03