Giter Site home page Giter Site logo

t4ts's People

Contributors

akoslukacs avatar cskeppstedt avatar daggmano avatar diullei avatar enoshixi avatar gbusbyms avatar igochkov avatar leandroshan avatar nied avatar swalters avatar vegardlarsen 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  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  avatar

t4ts's Issues

Generate class for each interface

The current implementation is perfect for getting data because you are just using the interface, but to support CRUD you need to be able to instantiate a class.

So how about rather than exporting interfaces you export classes and generate just a .ts file or also create the class that implements the interface?

..unless I've missed something?

Specify inheritance on typescript interface

Hello again..

Still loving the code!

So I have a BaseModel which all my models inherit from. When T4TS generates the interfaces it currently doesn't add the 'extends BaseModel' to the interface declaration.

Is it possible to do this (inferring from class definition)?

I hacked the code as I know my base type..

<#= module.IsGlobal?"":"export "#>interface <#= tsInterface.Name + (tsInterface.Name == "BaseModel" ? "" : " extends BaseModel") #> {

Thanks again.

BreezeJS support?

I made some very simple modifications to the T4TS.tt file in my solution so the generated enties better support BreezeJS. You can see my full T4TS file at https://gist.github.com/alexdresko/5393155 and a potentially helpful explanation for my madness at http://stackoverflow.com/questions/13817230/breeze-js-typed-entities/16028385#16028385.

I'm interested to know what you think about this idea as being an actual feature of T4TS, perhaps by way of an additional attribute like TypeScriptInterfaceAttribute.. maybe TypeScriptBreezeInterfaceAttribute?

How to build the project for deployment

Please excuse my ignorance. I've very new to T4. I was able to modify the project and verify that my modifications work in T4TS.Example project. But how do I get the .tt file updated that is in the build folder? Are there some utilities or commands that I don't see?

Thanks,

Shane

Error with partial classes

At first, I have to say that t4ts is really a practical thing. I use it to automatically generate TS interfaces from my Entity Framework classes.
However, I found a little bug. If you have a partial class and you add [T4TS.TypeScriptInterface] to both implementations, you get this exception:

Error 19 Running transformation: System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)
at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.TypeContext.AddCustomType(String typeFullName, CustomType customType) in \T4TS.tt:line 322
at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.CodeTraverser.<>c__DisplayClass3.b__2(CodeClass codeClass) in \T4TS.tt:line 100
at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.NamespaceTraverser.Traverse(CodeElements members) in \T4TS.tt:line 735
at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.NamespaceTraverser..ctor(CodeNamespace ns, Action1 withCodeClass) in \T4TS.tt:line 729 at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.CodeTraverser.<>c__DisplayClass3.<BuildContext>b__1(CodeNamespace ns) in \T4TS.tt:line 91 at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.ProjectTraverser.Traverse(ProjectItems items) in c:\Projects\P0900 BR Bauhandel\MasterDataManager\T4TS.tt:line 764 at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.ProjectTraverser.Traverse(ProjectItems items) in \T4TS.tt:line 768 at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.ProjectTraverser..ctor(Project project, Action1 withNamespace) in \T4TS.tt:line 753
at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.CodeTraverser.BuildContext() in \T4TS.tt:line 89
at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.CodeTraverser.GetAllInterfaces() in \T4TS.tt:line 109
at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.GetDataToRender() in \T4TS.tt:line 45
at Microsoft.VisualStudio.TextTemplating7B90580D93E684080705DF19CF6B1B1F04EA4B8FB10D9183C028C26006ED272AA3BCA78DE743602F8886F86B5820A9085A4D4B820EA3F5B48100BC224FE920EE.GeneratedTextTransformation.TransformText() in \T4TS.tt:line 14 T4TS.tt 322 1

Incorrect use of inherited classes

Given the following file:

[TypeScriptInterface]
public class ChildClass : ParentClass
{
    public string ChildProperty { get; set; }
}

[TypeScriptInterface]
public class ParentClass : GrandparentClass
{
    public string ParentProperty { get; set; }
}

[TypeScriptInterface]
public class GrandparentClass
{
    public string GrandparentProperty { get; set; }
}

The generated TypeScript file extends both ParentClass and ChildClass from GrandparentClass. Correct behaviour should be to extend ChildClass from ParentClass.

If GrandparentClass is declared at the top of the file, the correct behaviour is observed. This becomes a problem when working across multiple files as there is no way to ensure the correct declaration order.

A potential fix has been submitted. (Sorry, couldn't work out how to attach pull request to this issue).

Nice tool but getting out of date...any plans to maintain or any good replacements?

This tool saves time and is worth using, but doesn't handle IEnumerable, enum, uses bool instead of boolean, etc. In my case I'm using it for a one-time generation of interfaces so this is not a problem but generating t.ts files from C# is a great service that deserves support.

Are there plans to maintain this tool or any newer replacements?

Handle nullable properties without needing to decorate the property

Currently you have to specify nullable fields by decorating the property -

    [TypeScriptMember(Optional = true, Type = "bool")]
    public bool? IsMOJ { get; set; }

Is it possible to infer whether its optional from the nullable 'bool?'

Also when i declared my bool as nullable the output in the d.ts file set its type as 'any' and lost its actual type.

Add support for System.DateTimeOffset

For people like me, just add the following code on line 993 :)

                case "System.DateTime":
                case "System.DateTimeOffset":
                    if (Settings.UseNativeDates)
                        return new DateTimeType();
                    else
                        return new StringType();

Nested classes does not generate interfaces

I tried to generate nested classes interfaces but apparently it does not work - even after adding [TypeScriptInterfaceAttribute] to the inner classes.

Would it be hard to change the code to make this available?
I would be available to change the code.

camelCase

We use servicestack and its JSON serializer converts all POCO property names to camelCase.

Could we have an option to get T4TS to do this also?

TypeScriptInterface attribute for C# interfaces?

Hi!

Currently the TypeScriptInterfaceAttribute is defined only for C# classes AttributeTargets.Class. Have you checked, is there anything that would make it difficult to change it to allow interfaces as well?

Settings for specifying where to place the T4TS.d.ts file

As the subject says, an option in the settings file to specify where the T4TS.d.ts file is placed. I like to keep the root clean. I'm not sure its possible since most T4 is always placed in the root folder.

I guess I could also just move the T4TS.tt file.

TypeScriptInterface decorated classes in depended assemblies resolve to "any"

My solution consists of one assembly containing T4TS.tt and some classes decorated with TypeScriptInterface which in turn reference some types in a depended assembly which just references the T4TS attributes assembly. Unfortunately all references to types in the depended assembly resolve to type "any" when compiling T4TS.tt.

Custom place where the T4TS.d.ts file is generated

Hi,

It a great job! It saves a lot of typing time! Thanks for creating it! :)

I have two questions:

  • is there any way to setup that the T4TS.d.ts file is generated to a custom directory? For example, my Contracts are in a separated file, but the typescript files are placed in an webproject. I want the ts interfaces there and I don't want to copy if it is possible.
  • is there any option to set up the tool in the way where the result is 1 C# class / 1 typescript interface / 1 ts file? It would me more organized for me.

Thanks,

András

Add Support for C# @ Prefix

Once again, I have discovered something in which T4TS can be improved with a single line of code :)
If you have a property in c# prefixed with "@" (can be done to make properties have the name of a keyword), T4TS generates an invalid TypeScript file. In my case I had a propery named readonly in C# which resulted in a Syntax Error in TS. To fix this, just change line Line 143 to:
member.Name.StartsWith("@")? member.Name.Substring(1): member.Name

Support for IDicionary

I think IDicionary<string, object> should be outputed as { [name: string]: any} as this is what Newtonsoft.Json does when serializing .Net Objects to JSON

This is what my pull request #46 is for

Specify which project your model lives in

Hello

Great work by the way..

So my models live in a separate assembly to my T4TS template. The current implementation doesn't allow me to specify which assembly / assemblies I want to get my models from.

I hacked the code and changed the following in the GetDataToRender method..

// var generator = new CodeGenerator(project, settings);

// return generator.GetAllInterfaces().ToList();

var interfaces = new List<TypeScriptModule>();

foreach (Project proj in dte.Solution)
{
    if(proj.Name == "XYZ")
    {
         var generator = new CodeGenerator(proj, settings);
         interfaces.AddRange(generator.GetAllInterfaces().ToList());
     }
}

return interfaces;

}

Is it possible to get functionality like this in your code? Its a good feature request!

declare module is used even when CompatibilityVersion >= 1.5

TypeScript 1.5 introduced the declare namespace syntax as an alias for the declare module syntax in order to disambiguate external and internal modules. The recommended practice is to avoid the old declare module when declaring an what were called internal modules and are now called namespaces in TypeScript terminology. See microsoft/TypeScript/pull/2923 where Anders Hejlsberg explains the change.

Add setting to choose class or interface

Would it be possible to add an option to generate typescript classes instead of interfaces?

I have a C# class with a large number of attributes that I need to have a typescript object for. I really defeats the purpose of a generated class if I have to manually implement the interface.

Thanks
Joe

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.