Skip to content

Generator cannot support multiple types with the same name #296

@juliusfriedman

Description

@juliusfriedman

Consider

namespace SomeNamespace;
[TsInterface]
public class SomeClass { public int SomeIntMemeber; }
namespace AnotherNamespace;
[TsInterface]
public class SomeClass { public string SomeStringMemeber; }

When I generate TypeScript classes using a ClassCodeGenerator I get generated classes like so (when both types are used together)

import type { SomeClass } from './SomeNamespace/SomeClass ';
import type { SomeClass } from './AnotherNamespace/SomeClass ';

export interface SomeClass
{
  SomeClass: SomeClass;
  AnotherClass: SomeClass;
}

The visitor doesn't have access to the full type information, I am trying to investigate if a PropertyGenerator can help but it seems the type is already established by the time the PropertyGenerator has to declare the property so there is no way to accommodate this easily...

public class MyTypeScriptExportVisitor : TypeScriptExportVisitor {
public override void Visit(RtImport node)
{
    Write("import type ");

    if (node.Target != null)
    {
        Write(node.Target);
        Write(" ");
        WriteLine($"from '{node.From}';");
    }
    else
        WriteLine($"'{node.From}';");
}
}

For a work around in the meantime I use the Name attribute of the TsInterface and this gets the name to change and avoids conflicts in the generator.

If you can advise a way to avoid using the Name attribute and handle this directly in the generator / visitor it would be most helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions