After compilation, any variables declared within a module remain undefined

I have declared the following files

app.types.ts

/// <reference path="../../typings/tsd.d.ts"/>
module App{
    export var Module =     "website";
    //---------------Controller Base Types---------------
    export interface IScope extends ng.IScope {
        events: Controller;
    }
    export class Controller{
        protected scope: IScope;
        static id       : string;
        constructor($scope: IScope,controllerId:  string){
            this.scope        =     $scope;
            this.scope.events =     this;
            Controller.id                =      controllerId;
        }
    }
}

app.ts

    /// /// <reference path="app.types.ts"/>
    module App {
    "use strict";
    var app = angular.module(Module, [
        // Angular modules
        'ngMessages','ngAnimate','ngTouch','ngAria','ngSanitize',
        // Custom modules
        'ui.router','ui.bootstrap','ui.bootstrap.tpls'
        // 3rd Party Modules
    ]);
}

The code compiles to Js without errors but the variable Module is undefined across the file.

I also tried using App.Module but still the variable was undefined

Update : I have check the app.types.js is inserted in the html before app.js. There generated Js files seem to be incorrect.

//App.js
(function(){/// <reference path="app.types.ts"/>
var App;
(function (App) {
    "use strict";
    var app = angular.module(App.Module, [
        // Angular modules
        'ngMessages', 'ngAnimate', 'ngTouch', 'ngAria', 'ngSanitize',
        // Custom modules
        'ui.router', 'ui.bootstrap', 'ui.bootstrap.tpls'
    ]);
})(App || (App = {}));
}());

//App.types.js
(function(){/// <reference path="../../typings/tsd.d.ts"/>
var App;
(function (App) {
    App.Module = "website";
    var Controller = (function () {
        function Controller($scope, controllerId) {
            this.scope = $scope;
            this.scope.events = this;
            Controller.id = controllerId;
     }
     return Controller;
    })();
    App.Controller = Controller;
 })(App || (App = {}));
}());

Answer №1

It is advisable to include the following in your code:

/// <reference path="relative/path/to/app.types.ts"/>

In order to ensure the correct loading order of scripts, make sure to add this line to your app.ts file. It seems like currently app.types.js is being loaded after app.js.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I utilize ng-table for managing data in both admin and user interfaces, with distinct sources. The admin interface displays author data until refreshed

Using ng-table for both admin and user functionality within the same controller and view, each loading data from different URLs. However, there is an issue with data being reloaded from cache when accessing it, that I need to clear when a user logs out. C ...

Transform an Array<string> into an object with the strings of the array as keys

I am attempting to develop a type conversion method that transforms an array of strings into an object with the string values as keys. type ObjectFromKeys<T extends Array<string>> = { [K in keyof T]: string } declare const o: ObjectFromKeys& ...

What is the best way to output the leaf nodes from an array of object lists in TypeScript?

Having trouble with TypeScript, specifically working with arrays and filtering out leaf nodes. I want to print only the leaf nodes in the array, resulting in ['002', '004', '007']. Can someone please assist me? Excited to lear ...

Include a parameter in a type alias

Utilizing a function from a library with the following type: type QueryFetcher = (query: string, variables?: Record<string, any>) => Promise<QueryResponse> | QueryResponse; I aim to introduce an additional argument to this type without mod ...

Angular Custom Validator Error (Validation function must either return a Promise or an Observable)

I created a personalized validator for the phone field but I'm encountering an issue The validator should be returning either a Promise or an Observable. Basically, I just want to check if the phone number is less than 10 characters. HTML Cod ...

What is the correct approach to managing Sequelize validation errors effectively?

I am working on a basic REST API using Typescript, Koa, and Sequelize. If the client sends an invalid PUT request with empty fields for "title" or "author", it currently returns a 500 error. I would prefer to respond with a '400 Bad Request' ins ...

The type 'ElementClass' is lacking several key properties, specifically context, setState, forceUpdate, props, and refs

I'm currently developing a web application using NextJS with Typescript. During my testing phase with Jest+Enzyme, I encountered the following error message: ** Test suite failed to run TypeScript diagnostics (customize using `[jest-config].globals. ...

Variable passing value through google pie chart slices for offset

Using the Google Chart API and AngularJS, I am trying to set slice values through variables instead of hardcoding or using a foreach loop. How can I achieve this? In my code example below, the "selectedRow" variable is being passed as a string rather tha ...

Having trouble deploying Firebase Cloud function following the migration to Typescript

After following the steps outlined in the firebase documentation to convert my cloud functions project to TypeScript (see https://firebase.google.com/docs/functions/typescript), I encountered an error when attempting to deploy using 'firebase deploy - ...

The function "overloading" of the union type is not functioning properly

I attempted to "overload" a function by defining it as a union function type in order to have the type of the input parameter dictate the type of the `data` property in the returned object. However, this resulted in an error: type FN1 = (a: string) => { ...

The attribute 'map' is not found on the data type 'Observable<[{}, {}]>'

Struggling to incorporate map, PublishReplay, and other rxjs functions into Angular6, I keep encountering a compilation error stating "Property 'map' does not exist on type 'Observable<[{}, {}]>'" every time. The same issue arises ...

Transitioning my website to incorporate Angular JS

Recently, I have been exploring AngularJS and I am quite impressed with its features. I am currently developing a website using traditional methods (php, html, css, mysql, some jQuery) and I am considering transitioning to Angular. The reason for this chan ...

"I am looking to retrieve the properties of an object that belongs to the EChartsOption type in TypeScript when working with Angular and ECharts. How

Currently, I am exploring how to access a property of an EChartOptions object in Angular 16.0.2, which may be undefined as I am still new to TypeScript. List of npm packages: eapp/src$ npm list <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

What is causing this to function properly only during the initial display of the dialog?

When using ui-bootstrap with the attribute attached to the ok/save button on the dialog, I encountered an issue. The first time my dialog is created, it focuses on the button just as expected. However, every subsequent time it has no effect. .directive(&a ...

Using angular 1.X with webpack can be challenging and may cause compatibility issues

I am currently integrating webpack into my existing angularjs [1.4.7] application. I have a custom module that is being bundled using webpack and later added as a dependency in another module. While there are no errors during the bundling process, I encoun ...

Guide to implementing an $http post service with defer and promise in AngularJS

var myAppModule = angular.module('myApp', []); myAppModule.controller('mainController', function($scope, userService) { $scope.addUser = function() { var email = $scope.user.email; var password = $scope.user.password ...

Convert a boolean value to a string using filter in AngularJS

I am working on an AngularJS app and need to create a filter. In my database, I have a string value that indicates whether the data is active or inactive. I use 'S' for active and 'N' for inactive. I added a checkbox button on my page t ...

The absence of the @Injectable annotation is causing an issue when importing a JSON

I am currently in the process of integrating a JSON file into my service by using a @inject() tag within the constructor. Below is the code snippet I am working with. DependencyInjectionContainer.ts import { Container, decorate, injectable } from "invers ...

How can I successfully transmit the entire event during the (change) event binding with ng-select in Angular 14?

I'm working on Front end Code <ng-select formControlName="constituencyId" placeholder="Select Constituency" (change)='onContituencyChanged($event)'> > &l ...

Encountering issue while resolving flux/utils in webpack

My TypeScript OS project is in the process of being migrated to webpack, Unfortunately, I am currently facing a build error: ERROR in ./src/store/GigaStore.ts Module not found: Error: Cannot resolve module 'flux/utils' in /home/erfangc/GigaGrid ...