Giter Club home page Giter Club logo

cs-to-ts's People

Contributors

brunomlopes avatar richorama avatar umutozel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cs-to-ts's Issues

Class inherits from tree interface

Good afternoon, first of all thanks for the library. I have a question about converting Tree like structures to Typescript.

  • Question - yes
  • Bug - yes? maybe
  • code for playback
public interface ITree<T>
{
    public ulong Id { get; set; }
    public IEnumerable<T> Children { get; set; }
    public T? Parent { get; set; }
    public ulong? ParentId { get; set; }
}

public class Node : ITree<Node>
{
    public ulong Id { get; set; }
    public IEnumerable<Node> Children { get; set; } = new List<Node>();
    public Node? Parent { get; set; }
    public ulong? ParentId { get; set; }
    public string Title { get; set; } = null!;
}

var typeScript = CsToTs.Generator.GenerateTypeScript(typeof(Node));

expect result

export interface ITree<T> {
    id: number;
    children: Array<T>;
    parent: T;
    parentId?: number;
}

export interface Node extends ITree<Node> {
    id: number;
    children: Array<Node>;
    parent: Node;
    parentId?: number;
    title: string;
}

but got circular error

 at System.Linq.Enumerable.ToList[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at CsToTs.TypeScript.Helper.GetInterfaces(System.Type, CsToTs.TypeScript.TypeScriptContext)
   at CsToTs.TypeScript.Helper.PopulateTypeDefinition(System.Type, CsToTs.TypeScript.TypeScriptContext)
   at CsToTs.TypeScript.Helper+<>c__DisplayClass7_0.<PopulateTypeDefinition>b__0(System.Type)
   at System.Collections.Generic.List`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ForEach(System.Action`1<System.__Canon>)
   at CsToTs.TypeScript.Helper.PopulateTypeDefinition(System.Type, CsToTs.TypeScript.TypeScriptContext)
   at CsToTs.TypeScript.Helper+<>c__DisplayClass8_0.<GetInterfaces>b__1(System.Type)
   at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Cultu
re=neutral, PublicKeyToken=7cec85d7bea7798e]].ToList()

I find workaround

// Skip ITree interface, when converting node class
var text = Generator.GenerateTypeScript(new TypeScriptOptions()
{
    SkipTypePatterns = new [] {"ITree"},
}, typeof(Node));

// Convert separately tree interface
var skippedText = Generator.GenerateTypeScript(typeof(ITree<>));

// Contatenate text + skippedText and Save

With this use, we lose inheritance from the interface, but I did not find another workaround. I would appreciate any help, thanks!

Generics generate impractical entities

When translating C# generic new(), this will generate conditions impossible to satisfy

export class Company<TAddress extends Address & { new(): TAddress }> extends 
    BaseEntity<number> {
         Income: number;
         Name: string;
         EmployeeCount: number;
         Address: Array<TAddress>;
  }

This is making the claim that TAddress is and Address and a constructor which returns TAddress. Constructors don't return values.

Additionally, if you were to declare that TAddress has a parameterless constructor, you the generator should generate the Address entity compatible with the Company, but if you were to try to create a new Company

(). This will fail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.