dogusteknoloji / cs-to-ts Goto Github PK
View Code? Open in Web Editor NEW:factory: From C# to TypeScript.
License: MIT License
:factory: From C# to TypeScript.
License: MIT License
Good afternoon, first of all thanks for the library. I have a question about converting Tree like structures to Typescript.
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!
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.A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.