Error in Google Chrome caused by TypeScript

Here is a TypeScript file snippet that I'm working on:

module MyOrganization
{
    export module Software
    {
        export class VersionInfo
        {
            private _Major: number = 0;
            private _Minor: number = 0;
            private _Build: number = 0;
            private _Revision: number = 0;

            public get Major(): number { return (this._Major); }
            public get Minor(): number { return (this._Minor); }
            public get Build(): number { return (this._Build); }
            public get Revision(): number { return (this._Revision); }

            constructor(major: number, minor: number, build: number, revision: number)
            {
                this._Major = major;
                this._Minor = minor;
                this._Build = build;
                this._Revision = revision;
            }

            public toString(): string
            {
                return (this._Major.toString() + "." + this._Minor.toString() + "." + this._Build.toString() + "." + this._Revision.toString());
            }

            private static _LatestVersion: MyOrganization.Software.VersionInfo = new MyOrganization.Software.VersionInfo(1, 0, 0, 0);
            public static get LatestVersion(): MyOrganization.Software.VersionInfo { return (MyOrganization.Software.VersionInfo._LatestVersion); }
        }
    }
}

The LatestVersion static property is being accessed from an HTML file as shown below:

alert(MyOrganization.Software.VersionInfo.LatestVersion.toString());

Encountering some errors in Google Chrome:

TypeScript:

HTML/JavaScript:

Tried converting the static property to a function and even declaring a version instance but still facing the same issue. Any insights would be helpful!

Generated JavaScript code:

var MyOrganization;
(function (MyOrganization) {
    var Software;
    (function (Software) {
        var VersionInfo = (function () {
            function VersionInfo(major, minor, build, revision) {
                this._Major = 0;
                this._Minor = 0;
                this._Build = 0;
                this._Revision = 0;
                this._Major = major;
                this._Minor = minor;
                this._Build = build;
                this._Revision = revision;
            }
            Object.defineProperty(VersionInfo.prototype, "Major", {
                get: function () { return (this._Major); },
                enumerable: true,
                configurable: true
            });
            // Remaining code for properties, functions, and static property here...
        }());
        Software.VersionInfo = VersionInfo;
    })(Software = MyOrganization.Software || (MyOrganization.Software = {}));
})(MyOrganization || (MyOrganization = {}));

Answer №1

When you write code in a namespace, you can exclude the full namespace which not only improves readability but also reduces verbosity...

module HouseOfInformation
{
    export module Library
    {
        export class VersionNumber
        {   
            public static get CurrentVersion(): VersionNumber { return (VersionNumber._Current); }

            private static _Current: VersionNumber = new VersionNumber(1, 0, 0, 0);

            public get MajorVersion(): number { return (this.major); }
            public get MinorVersion(): number { return (this.minor); }
            public get BuildNumber(): number { return (this.build); }
            public get RevisionNumber(): number { return (this.revision); }

            constructor(private major: number, private minor: number, private build: number, private revision: number)
            {
            }

            public getVersionString(): string
            {
                return (this.major + "." + this.minor + "." + this.build + "." + this.revision);
            }
        }
    }
}

alert(HouseOfInformation.Library.VersionNumber.CurrentVersion.getVersionString());

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

Creating definitions for nested objects in TypeScript

I am dealing with a set of URLs for different buttons. These URLs are requested when the user clicks on one of three buttons: Input, Output, and StandardReport. The StandardReport button opens a window that contains three more buttons named Define, Valida ...

Access the Ajax response and store it in a JavaScript variable

I've successfully created a script that inserts data into an MySQL database using a modal and AJAX. However, I'm having trouble retrieving the response to complete an input field. Below is my current script: $.ajax({ url:"insertar_cl ...

Converting data types in TypeScript function parameters

Modify a function's parameter type by forcefully casting it. In the scenario displayed below: (<number>foo)(1) The original function definition is as follows: function foo( v : string ) ...

Issue with applying the React Material UI ThemeProvider

I'm having issues with applying styles using @material-ui/core in my React app. Some of the styles are not being applied properly. You can check out my sandbox for the full code (relevant snippets below). Although I followed the instructions from Ma ...

Is there a way to retrieve the operating system user name using Angular 6?

In order to ensure security for hospital staff using our app on Chromebooks, I am looking to retrieve the OS username and send it to a .NET web API. This API will then check if the user exists in the active directory and return their information. ...

Accessing a specific attribute of an object contained within an array

Currently, I am utilizing Vue.js in my project and have implemented a method that involves comparing values from two different arrays. array1: [{ name: 'test1', somevar: true }, { name: 'test2', somevar: false }] array2: ['test1 ...

Implementing fetch API in middleware in Next.js

Currently, I am utilizing a middleware in Next.js (https://nextjs.org/docs/advanced-features/middleware) for my project. However, I am encountering an issue when trying to send a request to the API. The error message displayed is: "unhandledRejection: Ty ...

Developing a unique drag-to-select feature for screen capturing on Google Chrome

I have scoured the internet high and low in search of a solution to this issue. I've even delved into different extensions to try and figure out how it can be accomplished. What is the most straightforward method to add a functionality to my extension ...

Create a JavaScript button that redirects to a different page within a React application

I am creating a div element using a for-loop and I want to link each div to the "/campaign" page with its respective id. When a div is clicked, I want it to navigate to the "/campaign/id" page and pass the id to the Campaign component. class Home extends ...

Setting Javascript variables - listing elements

I have created a menu where I want to assign a variable to each li item and display an alert with its text when clicked. I managed to achieve this using the script provided below. $("ul#menudropd .animal li a").click(function() { var whatever = $(this ...

Unable to retrieve Object property using computed method in Vue 3 vuex results in undefined value

When attempting to display the values of a computed property in the template using the syntax {{todo[0]['title']}}, I am receiving an 'undefined' output. However, using {{todo[0]]}} allows me to render the entire object. My goal is to b ...

Transform json nested data into an array using JavaScript

Can anyone assist me in converting Json data to a Javascript array that can be accessed using array[0][0]? [ { "Login": "test1", "Nom": "test1", "Prenom": "test1p", "password": "124564", "Email": "<a href="/c ...

JavaScript objects compared to arrays and JSON format

After countless hours of searching and frustration, I am still struggling to clearly define the distinctions between json, objects, and arrays (in javascript). Take a look at how I've been working with 2-dimensional data containers (trying to avoid us ...

How do I retrieve the date from a dynamically generated text field within an ng-repeat loop and pass it

I have a specific issue with accessing the value of dynamically created input text in my web form. The problem arises when using ngRepeat to manage items, particularly with $scope.newValueItem being undefined. How can I retrieve the value from dynamically ...

Determination of the input parameters

Currently, I am developing an Angular application that includes a matInput field for user input. The issue I am encountering is that when the user enters a positive or negative value in the field (e.g. +5 or -5), the final output does not reflect the inten ...

What should we do to resolve the uncommon use of the 'this' es-lint error? Which rule should we disable?

Recently, I encountered an issue with my Nuxt setup that is configured with el-lint and prettier. Every time I try to use 'this' within my template, it throws up an error unexpectedly. 6:15 error Unexpected usage of 'this' vue/this ...

Issue uploading with Candy Machine Version 2/ complications with directory

For some reason, I am encountering issues with the upload operation. Switching from relative to absolute paths did not resolve the error, and using the -c flag for the directory containing images and JSON files is causing a problem. However, other flags ...

Concerning the development of React components

Currently, I am diving into the world of React and ES6. Along this learning journey, I came across an interesting code snippet below. import { getBoxStyle } from './PythagorasTree.js' export const TreeBox = (props) => { const style = getBox ...

React compatibility problem with Internet Explorer 11

I'm encountering a problem with an error message stating "Expected identifier" in this code snippet. Any thoughts on what might be causing this issue? It seems like the problematic section of the code is originating from the transpiled version of th ...

Send dropdown selections to a Javascript function and convert them into an array

Within my JavaScript function, I need to pass multiple selected values from dropdown menus and store them in a JavaScript array. Each time a value is selected and sent using the onchange() function, it should be added to the array. If the same value is sel ...