Reinforced.Typings does not generate fully qualified names (FQN) for types when UseModules is set to true or false

Overview:

Within my solution, I have two projects: ProjA and ProjB. In ProjA, I've defined a custom RTConfigure method to streamline the configuration process for translating C# to TypeScript using the Reinforced.Typings tool. Meanwhile, ProjB houses C# ViewModel classes that are meant for translation.

Issue at Hand:

While working in ProjB, I encountered an issue with three classes residing in separate files, each belonging to its unique namespace. When utilizing a global builder configuration through builder.UseModules(true, false), the resulting code fails to include fully qualified namespace names for types referenced after the extends keyword or when specified as members of a different class (belonging to a distinct namespace from the used member's type).

Illustrative Example:

  1. ProjB.Ns1.Class1
  2. ProjB.Ns2.Class2
  3. ProjB.Ns3.Class3

All three classes feature just two basic properties, with Class3 slightly differing by having an additional property of the type Class1. Furthermore, Class2 inherits from Class1.

Sample Code Snippets:

// Class1.cs
namespace ReinforcedTypings.DifferentNamespaces.Ns1
{
  public class Class1
  {
    public int AnIntegerPropNs1 { get; set; }
    public string AStringPropNs1 { get; set; }
  }
}

// Class2.cs
using ReinforcedTypings.DifferentNamespaces.Ns1

namespace ReinforcedTypings.DifferentNamespaces.Ns2
{
  public class Class2 : Class1
  {
    public int AnIntegerPropNs2 { get; set; }
    public string AStringPropNs2 { get; set; }
  }
}

// Class3.cs
using ReinforcedTypings.DifferentNamespaces.Ns1

namespace ReinforcedTypings.DifferentNamespaces.Ns3
{
  public class Class3
  {
    public int AnIntegerPropNs3 { get; set; }
    public string AStringPropNs3 { get; set; }
    public Class1 AClass1PropNs3 { get; set; }
  }
}

The config method is straightforward and defined as follows:

  public static class RTConfig
  {
    public static void Configure(ConfigurationBuilder builder)
    {
      var types = typeof(ReinforcedTypings.DifferentNamespaces.Ns1.Class1).Assembly.GetTypes().ToList();

      builder.ExportAsClasses(types.Where(x => x.IsClass), c => c.WithAllFields().WithAllMethods().WithAllProperties());
      builder.Global(c => c.UseModules(true, false));
      // ^ commenting out this line will also cause a different error
    }
  }

I utilize the .xml configuration file to specify that all translations should be consolidated into one file by setting the following option (false) like so:

<RtDivideTypesAmongFiles>false</RtDivideTypesAmongFiles>

This results in the ensuing TypeScript code (saved in translated.ts as configured in the .xml file):

export namespace ReinforcedTypings.DifferentNamespaces.Ns3 {
    export class Class3
    {
        public AnIntegerPropNs3: number;
        public AStringPropNs3: string;
        public AClass1PropNs3: Class1; // <- error here
    }
}
export namespace ReinforcedTypings.DifferentNamespaces.Ns2 {
    export class Class2 extends Class1  // <- error here
    {
        public AnIntegerPropNs2: number;
        public AStringPropNs2: string;
    }
}
export namespace ReinforcedTypings.DifferentNamespaces.Ns1 {
    export class Class1
    {
        public AnIntegerPropNs1: number;
        public AStringPropNs1: string;
    }
}

It's noteworthy that Class1 lacks the full namespace designation after extends, leading to issues locating these types in TypeScript due to the absence of the complete path name.

Addendum Issue Observed:

Should you opt out of utilizing UseModules, and consequently comment out that line, another complication arises within the generated TypeScript code pertained to the order of translation. Specifically, Class1 may not be recognized within Class3 as it is referenced before being declared.

In Conclusion:

Though I haven't delved deep into the source of RT, a potential point of concern lies in the UseModules(true, false) function where the second argument explicitly denounces discarding namespaces, alongside an issue concerning the sequencing of outputted code. With the second argument set to false, one would anticipate consistent usage of FQN for all desired types. Should there be any misconceptions regarding the utilization of this config parameter, I propose the implementation of a universal configuration that mandates the use of FQN for all/relevant types, which could greatly enhance the workflow.

Answer №1

Indeed, the FQN problem is a known bug in RT and has been resolved in version 1.4.6.

Regarding the additional issue: you can find more information by visiting this GitHub Discussion

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

Configuring the tsconfig outDir will specify where the output files will be stored

What am I missing in the tsconfig settings if I only want to output files in the root directory? If I set it as "rootDir":"src" "outDir":"build", or "rootDir":"src" "outDir":"&q ...

Angular: How to Disable Checkbox

Within my table, there is a column that consists solely of checkboxes as values. Using a for loop, I have populated all values into the table. What I have accomplished so far is that when a checkbox is enabled, a message saying "hey" appears. However, if m ...

Typescript error: The value "X" cannot be assigned to this type, as the properties of "Y" are not compatible

Disclaimer: I am relatively new to Angular2 and typescript, so please bear with me for any errors. The Challenge: My current task involves subtracting a start date/time from an end date/time, using the result in a formula for my calculation displayed as " ...

Sorting data by percentages in AngularJS

I am currently facing an issue with sorting percentages in a table column. Despite using methods like parseFloat and other AngularJS (1.5.0) sorting techniques, the percentages are not being sorted as expected. [ {percentage: 8.82} {percentage: 0. ...

Having trouble displaying images when uploading to a remote server

I recently uploaded my website to a remote server, but I am encountering an issue with viewing the images that I have referenced in the following code block: <a href="ProductDetails.aspx?productID=<%#:Item.ProductID%>"> <img src="/C ...

The Angular Material date picker unpredictably updates when a date is manually changed and the tab key is pressed

My component involves the use of the Angular material date picker. However, I have encountered a strange issue with it. When I select a date using the calendar control, everything works fine. But if I manually change the date and then press the tab button, ...

Interface of TypeScript Undetermined

Currently, I am developing a Demo API Wrapper specifically for Roblox. During the development process, I have come across a certain issue that I would like to address. My aim is to send a request and then return all the data in the manner of an API wrapper ...

Ways to invoke a function in Angular2 when the Boolean condition is met

Within my component class, I have implemented a popup function along with a Boolean flag that returns true or false based on specified conditions. In the template class, I want the popup function to be triggered when the flag becomes true, displaying a pop ...

Errors caused by Typescript transpilation only manifest on the production server

During the process of updating my node version and dependencies on both machines, I came across an issue where building my app in production on one machine resulted in an error, while building it on my main machine did not. I found that the errors disappe ...

TimeoutException Automatically Triggered by Selenium WebDriver in C#

We are in the process of transitioning our automation scripts from Selenium RC to WebDriver. I have encountered a few challenges with WebDriver, particularly when TimeoutExceptions are thrown immediately after any changes are made on the web page being tes ...

Instantiate the component array upon object instantiation

I'm currently in the process of learning Angular 2, so please bear with me if this question seems trivial. I am attempting to create a dynamic form that can be bound to a model. However, I am encountering an issue where I am unable to initialize my ar ...

Angular 2: Issue with Table not Being Updated

https://i.stack.imgur.com/qLDUZ.png The UsersList component opens a new page upon clicking the table. https://i.stack.imgur.com/WwqIX.png After changing and saving user values, the updated value is not immediately reflected in the grid for the first tim ...

Definition of Promise resolve type in Visual Code's d.ts file

Need help with: // api.js export function getLayout(){ return axios.get('/api/layout').then(res => res.data) } // api.d.ts declare interface JSONResponse { meta: object, data: Array<Field> } export declare function getLayout ...

The error message "Module 'electron' not found" is commonly encountered when working with Electron and TypeScript

Hey there! I'm having some trouble with Electron not supporting TypeScript on my setup. I'm using vscode 1.16.1 and here is an overview of my package.json: { [...] "devDependencies": { "electron": "^1.6.13", "ts-loader": "~2.3.7", ...

Elevate the Appearance of Material UI Elements with custom CSS Sty

I am currently facing an issue while trying to customize the styling of a Material UI component using CSS. Here is the code snippet: <IconButton className="my-class"> <Close /> </IconButton> CSS: .my-class { float: right ...

How can I achieve the same functionality as C# LINQ's GroupBy in Typescript?

Currently, I am working with Angular using Typescript. My situation involves having an array of objects with multiple properties which have been grouped in the server-side code and a duplicate property has been set. The challenge arises when the user updat ...

The logo emerges from the background color, with the text consistently appearing in black

In my attempt to display a logo and text together in an Outlook page, I encountered an issue. The content from the HTML page appears different when sent to MS Outlook. Despite not using flexbox in my HTML code, Outlook interprets it differently. I am uncer ...

What is the best way to automatically include a dependent DLL when a client solution is referencing my project?

In my C# project, I have developed a library DLL called myLib.dll which relies on an external third-party DLL called dep.dll. When others want to use my library by adding it to their solutions and referencing it, only myLib.dll gets automatically copied to ...

Retrieve the product IDs by selecting the checkboxes, then compile a fresh array consisting of the identified IDs

I am currently delving into the realm of typescript/angular2+ as a fledgling student, and I have taken on the task of creating a website to put my newfound knowledge to the test. The view is up and running, but I'm facing some roadblocks as I work on ...

Differences between Typescript and Node versions

Is there a connection between the version of Typescript and the version of Node since Typescript is a global npm module? In other words, is there a minimum Node version required to run a specific version of Typescript. ...