Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript's import unable to resolve external module

I'm trying to import an external class (written in Typescript) into another Typescript class using requireJS. I used this syntax but I don't understand why I'm getting a syntax error with this import statement:

enter image description here

I have also tried using this instead:

import t = module("Controller/TestController");

And I'm also getting the same error.

The above import/require statement resides in appmod.ts. This is my file structure:

+Root
  +Scripts
    +app
      -main.ts
      -appmod.ts
      +Controller
        -TestController.ts

I have looked through the documentation, and this line looks perfectly fine to me. The file TestController.ts does exist in the path and the classes are prepended with export keyword.

What's wrong with this line?

This is how my TestController.ts look:

/// <reference path="../typings/angularjs/angular.d.ts" />

module testApp.Controller {
     export interface ITestScope extends ng.IScope {
         helloString:string;
     }

     export class TestController {

         public static $inject = [
            "$scope"
         ];


         constructor(private $scope: ITestScope) {
            this.$scope.helloString = "Hello!";
         }
     }

 }

I've used DefinitelyTyped's AngularJS definition in my TestController.js.

like image 517
Carven Avatar asked Oct 20 '22 10:10

Carven


1 Answers

Your export statement needs to be at the root level in your file. Remove the redundant module http://m.youtube.com/watch?v=KDrWLMUY0R0&hd=1

I.e. Delete 'module testApp.Controller'

like image 67
basarat Avatar answered Oct 28 '22 15:10

basarat