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?

4
  • 1
    What version of TypeScript are you using? Commented Aug 16, 2016 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 Commented Aug 16, 2016 at 22:17
  • 1
    You might want to start looking into the import keyword, since you're using a version which supports it. It takes over for the /// <reference comments and provides an experience more in line with recent versions of ECMAScript. I'm not sure why you're getting this error, but it could have to do with the way the files are compiled. Commented Aug 16, 2016 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 Commented Aug 16, 2016 at 22:28

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.