Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-referencing class creates duplicate identifier #8

Closed
daveriedstra opened this issue Jul 17, 2017 · 7 comments

Comments

Projects
None yet
2 participants
@daveriedstra
Copy link

commented Jul 17, 2017

public class MyClass {
    public MyClass MyMember { get; set; }
}

generates typescript file my-class.ts:

import { MyClass } from "./my-class";
export class MyClass {
    myMember: MyClass;
}

which gives typescript error [ts] Import declaration conflicts with local declaration of 'MyClass'. It's easy enough to delete the self-referential import, but it will get recreated the next time TypeGen is run.

(This is in TypeGen v1.5.5)

jburzynski added a commit that referenced this issue Jul 18, 2017

- github #8 Self-referencing class creates duplicate identifier
- github #9 Generic type parameters 'extends' in member type
@jburzynski

This comment has been minimized.

Copy link
Owner

commented Jul 18, 2017

Should be fixed in v1.5.6 (just uploaded to NuGet).

@daveriedstra

This comment has been minimized.

Copy link
Author

commented Jul 18, 2017

That fixed it in 2 of 3 cases, but there's still one case where the generated class file is attempting to import itself. Here's an overview of the C# model file, maybe something will stand out.

// usings ... 
namespace NS.NS
{
  // more usings

  [ExportTsClass]
  public class MyClass : BaseClass<Guid>
  {
    public MyClass MyMember { get; set; }
    [TsType(TsType.String)]
    public Guid? MyMemberId { get; set; }

    public List<MyJoinClass> MyJoins { get; set; }

    // a pile of other members with other types (ie, not MyClass or MyJoinClass)
  }

  public class MyJoinClass
  {
    public MyClass Class { get; set; }
    [TsType(TsType.String)]
    public Guid ClassId { get; set; }

    public MyOtherClass OtherClass { get; set; }
    [TsType(TsType.String)]
    public Guid OtherClassId { get; set; }
  }
}
@jburzynski

This comment has been minimized.

Copy link
Owner

commented Jul 20, 2017

I wasn't able to replicate the error based on this example. When I tried it, MyClass only imports MyJoinClass (because I don't have properties of any other types in MyClass).

Which class is importing itself in your case? Is it MyClass or MyJoinClass?

Also, have your tried deleting the project's bin folder? I found that it helps sometimes, although I'm not sure in which cases exactly.

@daveriedstra

This comment has been minimized.

Copy link
Author

commented Jul 20, 2017

Interesting. It's MyClass that's importing itself. I tried removing the bin folder but it didn't fix the issue. Annotating MyClass.MyMember with [TsIgnore] removes the problematic import (but of course, also the property, which we need).

@jburzynski

This comment has been minimized.

Copy link
Owner

commented Jul 20, 2017

Just to be on the safe side - can you check if TypeGen or TypeGen -h shows version 1.5.6?

Also, I've noticed that in my case there's an error when a class inherits from a base class which has Guid as a generic parameter (it can't recognize the Guid type). Can you make sure that it isn't this scenario that's causing an error in your case? I.e. can you make sure that in the file content there actually is an 'import' that's importing the class itself?

I've just tried to generate my example (based on your case) with TypeGen.exe downloaded and unpacked directly from nuget.org and it seems to work fine, so I can't really see where the problem is. Maybe you can also try to use the TypeGen.exe from direct NuGet download to rule out this possibility as well?

Other than that I'm not really sure what can be causing this error.

@daveriedstra

This comment has been minimized.

Copy link
Author

commented Jul 21, 2017

ack I'm so sorry, I forgot to update the .exe to 1.5.6! Updating it fixed everything.

With Guid I have a <custom-head> which imports a simple typescript Guid class. This has been working well for some time now.

export class Guid extends String {}

This is fixed so I'll close it. Thanks for your help and sorry again.

@jburzynski

This comment has been minimized.

Copy link
Owner

commented Jul 21, 2017

No problem, glad I could help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.