0

I know that the TypeScript outFile usage is not recommended.

But I am forced to use it until I have time to implement a better solution such as AMD.

I believe I am having a "module splitting issue". I have two files in the same directory:

File referencedFile.ts:

module my.namespace {

   export class one {
   }

   export class two {
   }
}

File anotherClass.ts:

module my.namespace {
  export class anotherClass {
      constructor() {
         // THROWS ERROR "JavaScript runtime error: Object doesn't support this action"
         var x = new my.namespace.one();
      }
   }
}

At runtime, I get the error "Object doesn't support this action" when trying to instantiate a new "one" class. Debugging in anotherClass's constructor, I can see my.namespace.one and my.namespace.two don't exist at this point.

I added this line at the top of anotherClass.ts and it didn't resolve:

/// <reference path="referencedFile.ts" />

My typescript Visual Studio settings "Combine Javascript output into one file: Scripts\oneFile.js"

I can see in the generated "oneFile.js", the code from referencedFile.ts is there, and it is in the file before the code from anotherClass.js so I don't think there is an ordering issue.

What gives?

user210757
  • 6,996
  • 17
  • 66
  • 115
  • 1
    What version of TypeScript are you using? – Heretic Monkey Aug 16 '16 at 22:04
  • 1.8.36 listed in VS 2015, but I had 1.7.6 tools installed in program files. I removed the 1.7.6 tools and this may have resolved. Will verify but would like to understand why – user210757 Aug 16 '16 at 22:17
  • 1
    You might want to start looking into [the `import` keyword](https://www.typescriptlang.org/docs/handbook/module-resolution.html), since you're using a version which supports it. It takes over for the `/// – Heretic Monkey Aug 16 '16 at 22:21
  • I think I may have to make the move to external modules to use the import keyword but is definitely where I want to go – user210757 Aug 16 '16 at 22:28

2 Answers2

1

From : // THROWS ERROR "JavaScript runtime error: Object doesn't support this action"

Clearly the ordering is wrong.

Specify ordering with outFile

You can use the good ol reference file trick. This is documented well here : https://github.com/TypeStrong/grunt-ts#javascript-generation

PS: I am sure you know my opinions on the subject : https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html but still worth mentioning for other people.

basarat
  • 261,912
  • 58
  • 460
  • 511
  • Great info. The issue ended up being having typescript 1.7.6 installed even though I had 1.8.36 installed with VS 2015. And yes on the P.S. - I included that link in my question – user210757 Aug 17 '16 at 15:01
0

The issue ended up being having typescript 1.7.6 installed even though I had 1.8.36 installed with VS 2015

user210757
  • 6,996
  • 17
  • 66
  • 115