reinforced / reinforced.typings Goto Github PK
View Code? Open in Web Editor NEWConverts C# classes to TypeScript interfaces (and many more) within project build. 0-dependency, minimal, gluten-free
License: MIT License
Converts C# classes to TypeScript interfaces (and many more) within project build. 0-dependency, minimal, gluten-free
License: MIT License
I'm trying to generate typescript with Reinforced.Typings and I have a problem with DateTime? type. In build output I have an info that Type resolution failed with code RT0003. I could use builder.Substitute for choose type manually but I think that this type should be resolved automaticly?
Is it by design that DateTime C# type are translated to any type in TypeScript?
I am having trouble defining some configurations based on an enum.
[email protected]
[email protected]
[email protected]
eg.
In file MyEnum.ts produced by Reinforced Typings
module Vm {
export enum MyEnum {
Created = 0,
Waiting = 1
}
}
In file MyConfig
export const MyConfig = {
[Vm.MyEnum.Created]: {
shortMessage: 'Created',
longMessage: 'A much longer explanatory message'
}
/* etc */
}
Without the 'const' typescript is leaving the value MyEnum.Created
in the output object and run time crash.
I found some info about how adding const
to the enum causes the compiler to replace the identifier with the integer, which would at least get this working... [code base came from from typescript 1.8]
It is quite possible I am just being naive and have done it the hard way, I would appreciate a pointer in the right direction if that is the case.
Hi guys,
When do you plan to release 1.3.0 version?
I find that using the Fluent api, my classes being exported to interfaces do not maintain their inheritance chain. I have also not yet found any way to configure it to work. Is it possible i am missing something, or is the feature not implemented?
There are times when the interface generated needs to specifically use pascal case (MVC SelectListItem), but we much like setting RtCamelCaseForProperties
true. We could do it by setting RtCamelCaseForProperties
false and then adding the [TsProperty(ShouldBeCamelCased: true)]
on every property but that is pretty messy.
What I'd love is if there would be the opposite, that we could just use [TsProperty(ShouldBePascalCased: true)]
on the properties that need it for compatibility with MVC.
Hi, I believe this should work, given the documentation?
That is, if I adorn my C# class with [TsClass]
and set the attribute [TsProperty(ForceNullable = true)]
- it should generate the TypeScript nullable "?" syntax
I believe it's due to this line of code in PropertyCodeGenerator.cs ?:
if (tp.ForceNullable && element.DeclaringType.IsExportingAsInterface() && !Context.SpecialCase)
Which seems to limit the ForceNullable generation to interfaces (TsInterface)
It appears that a C# class called ExternalUser
will produce a TypeScript definition called IExternalUser
, as expected, however a C# class called InternalUser
will produce a TS defn called InternalUser
. There must be some logic to check for leading I
's somewhere, but some improvement may be required...
Hi,
I would like to add breakpoint in some line in Configure method. How could I debug it?
When generating ts classes with RT, they are either generated within a module as "export class" or without a module (IncludeNamespace=false) - but then without the export keyword.
I miss the option of generating "export class"es without the module/namespace.
The Angular2 team constantly uses "export class" without the module in their examples (for example https://angular.io/docs/ts/latest/guide/displaying-data.html), this leads me to believe that it would be valid to have an export class without a module.
Something about the below class being present in the project causes RTCLI to throw an exception.
public class Broken : Swashbuckle.Swagger.IOperationFilter
{
public void Apply(Swashbuckle.Swagger.Operation operation, Swashbuckle.Swagger.SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription)
{
}
}
The class requires the library Swashbuckle.
The exception:
Reinforced.Typings : Unexpected error RT0999: Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) (TaskId:47)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) (TaskId:47)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) (TaskId:47)
at Reinforced.Typings.Cli.Bootstrapper.<>c__DisplayClass2.<ResolveFluentMethod>b__0(ConfigurationBuilder builder) (TaskId:47)
at Reinforced.Typings.TsExporter.Initialize() (TaskId:47)
at Reinforced.Typings.TsExporter.Export() (TaskId:47)
at Reinforced.Typings.Cli.Bootstrapper.Main(String[] args) (TaskId:47)
I have a very large, very complex multi-solution system spanning both .NET 3.5 and .NET Core 1.0 compilations for my POCO. Now we're doing some Angular stuff for database maintenance chores and need to share out the POCOs as TS files, so I built a skeleton non-core .NET console project, added Reinforced.Typings, then referenced my DLL in the configuration as follows:
<ItemGroup>
<RtAdditionalAssembly Include="$(SolutionDir)....\ClientLibraries\DataDef\bin\Debug\net35\DataDef.dll" />
</ItemGroup>
The problem is that VS says RtAdditionalAssembly is not a valid child of ItemGroup. This is VS2015 Update 3 with all patches as of Aug 2016.
Is there any way we could inform Reinforced.Typings to use string
TS-type for System.Guid
C#-type? Right now TypeResolver
outputs RTW0003_TypeUnknown
warning and assumes any
TS-type.
Code generator Reinforced.Typings.Generators.EnumGenerator has thrown an error: Object reference not set to an instance of an object.
I'm trying to work with Enums, using two projects - the main website (which has some TsInterface use in it including TsEnum which works nicely) and a "core" dll that is referenced by the main website, which also contains some models. I've added the "core" library to the settings.xml using RtAdditionalAssembly and it sort of works, but I get this error.
Could you output symbols on the nuget package so I could see line numbers to help diagnose/fix this issue?
Hi guys,
I've got compiler error: "Code generator Reinforced.Typings.Generators.ClassCodeGenerator has thrown an error: Length cannot be less than zero."
I'm using fluent configuration.
After building the project only ts.tmp file is generated and there's no ts file.
Everything worked properly before and I can't remember any source code change.
Gist Github with Reinforced.Typings.settings.xml and InterfacesBuilder.cs: https://gist.github.com/urbanmichal/6578576f42f9be2572c575fe5a9d7da5
I will be grateful for any help you can provide.
Sorry just disregard this Issue, it was a mistake from my side. I'm very new to Typescript and thought it had a DateTime type, but not. By mistake i was looking at wrong documentation.
I see now that there is no datetime type so any must be the resolved type.
I cant seem to delete the issue.
BR and thanks for a great and helpfull tool.
Peter Meldgaard
Hi guys,
Is there any way to generate methods, which name doesn't starts with "Begin" or "End" phrase?
Pseudocode:
.ExportAsInterfaces(proxyInterfaces, conf => conf.WithPublicMethods(publicMethod =>
!publicMethod.GetType().Name.StartsWith("Begin")
&&
!publicMethod.GetType().Name.StartsWith("End")));
My class/interface members are being camelCased even when I explicitly set them to not be.
I created and use the following extensions:
public static T WithEverythingThatIsPublic<T>(this T builder) where T : ITypeConfigurationBuilder
{
return builder
.WithPublicMethods(c => c.NotCamelCase())
.WithPublicFields(c => c.NotCamelCase())
.WithPublicProperties(c => c.NotCamelCase());
}
public static T NotCamelCase<T>(this T config) where T : IExportConfiguration<ICamelCaseableAttribute>
{
config.AttributePrototype.ShouldBeCamelCased = false;
return config;
}
but the output members are always camelcase.
It seems that .NET Core
is unsupported.
However, it allowed to install the NuGet package (not specified framework versions in the .nuspec
files?) for a netcoreapp1.1
project, but any references to the classes can't be resolved.
Should we expect .NET Core support of the project?
Reinforced.Typings.TypeExtensions.IsTuple doesn't check for System.ValueTuple and returns false, causing all ValueTuples to map to any. Can support for ValueTuple be added?
Basically, this:
I'm not sure if it's a bug, but I guess it shouldn't happen at least in the default configuration.
Here is the example from the screenshot:
reinforced_class_used_before_its_declaration.zip
[EDIT] After further investigation, I found that the culprit is the References parameter in Reinforced.Typings.Targets. When a project has a lot of references, the exe cannot be invoked as the argument becomes too long for Windows to handle (ugh).
If I try changing the code to give a smaller number of References, I get errors that certain assemblies cannot be loaded. Is there a way for the program to infer the references? It seems crazy that all the project's references need to be passed in like this.
I'm happy to work on a fix but I'm not sure what form that fix would take.
[ORIGINAL POST]
When I try to build the project after freshly installing Reinforced.Typings, I get the following error:
The specified task executable "rtcli.exe" could not be run. The filename or extension is too long
I checked, and the full path to rtcli.exe
is only ~70 characters long.
Any idea what could be causing this issue?
Do you create some kind of log or something? Because "rtcli.exe" exited with code 1." tells nothing unfortunatelly.
Example. Given
public abstract class A
{
public B SomeProperty {get;set;}
}
public class C : A
{
}
I'd expect ExportAsClasses(new []{typeof(C)})
to generate classes for B, A and then C. Instead I got only class C without any properties.
We came across this issue for some of our bitfield enums. For example, here is a enum that would pose problem:
[Flags] [TsEnum(IncludeNamespace = false)]
public enum UserGroup
{
None = 0x00,
Administrator = 0x01,
Standard = 0x02,
Restricted = 0x04,
Guest = 0x08,
RestrictedAndLower = Restricted | Guest,
Default = Standard,
}
and here is the Typescript generated:
export enum UserGroup {
None = 0,
Administrator = 1,
Standard = 2,
Standard = 2,
Restricted = 4,
Guest = 8,
RestrictedAndLower = 12,
}
(Notice the the Standard
key is duplicated and the Default
key is missing)
Is there any problem with generating code for partial class?
Hello.
vNext (Mvc 6.0) ?
As it it now the generated file is generated with tab indentation. I would like to be able to change this to be spaces instead.
When building a signed module that makes use of reinforced.typings, I get the following compiler error:
CSC : error CS1577: Assembly generation failed -- Referenced assembly 'Reinforced.Typings' does not have a strong name
Can you update the nuget package with a signed library?
I have an issue after including reinforced typings, that all my typescript get's compiled in their folder instead of what is specified in the tsconfig.json,
Hopefully, you can point out an error I might have made.
Reinforced.typings.settings.xml:
If I put the import project for reinforced typings above, it won't run at all.
Hi.
There is an issue with order of generated export class
es. Reinforced.Typings builds following code:
module MyModule {
export class Abc extends MyModule.Def { }
export class Def { }
}
And this causes TypeScript error:
error TS2690: A class must be declared after its base class.
Both Reinforced.Typings.dll and Reinforced.Typings.Integrate.dll are distributed via NuGet as not signed assemblies.
This is a blocking problem, since it prevents usage of Reinforced Typings in any project that involves signed assemblies.
I just wanted to check that this is deliberate
On updating to 1.3.7 from 1.3.0 I found that this C# field, decorated with attribute [TsClass] now creates a typescript field that isn't optional
public int? StartPageID { get; set; }
TypeScript output:
public startPageID?: number; // 1.3.0
public startPageID: number; // 1.3.7
Admittedly, I wanted to use TsInterface for this but my team mate has forced me to use TsClass for some reason
I would like to use the ForceNullable Attribute on Class/Interface Level so that all Properties of the Class/Interface are optional in the resulting ts.
=>
Forces all properties to be nullable. E.g. field:boolean becomes field?:boolean when you specify [TsInterface(ForceNullable = true)] in attribute configuration
Is that something that could be interesting to others?
Hey,
One question - I'd like to generate the enum declaration in non-definition files (just .ts) while all the interfaces go into .d.ts files. Is that possible?
Automatic generation of index.ts
file containing imports would be a pretty neat feature. AFAIK right now if we're using modules we need to import each file independently in TS code:
import { ContractA } from "contracts/ContractA";
import { ContractB } from "contracts/ContractB";
import { ContractC } from "contracts/ContractC";
import { ContractD } from "contracts/sub/ContractD";
import { ContractE } from "contracts/sub/ContractE";
If Reinforced.Typings would generate two index.ts
files inside contracts
and contracts/sub
directories we would be able to improve readability:
import { ContractA, ContractB, ContractC } from "contracts";
import { ContractD, ContractE } from "contracts/sub";
[JsonIgnore,TsProperty(Name = "ID", ForceNullable = true)]
protected virtual int _id { get { return 0; }}
Gives me below, when settings are for Camel Case, but I don't expect camel case settings to override an explicit setting of the "Name"
export interface IDomainObject
{
id?: number;
}
The only thing I've changed in my codebase, to get this error, is to move my tsconfig.json
Which technically, has nothing to do with Reinforced.Typings, since it doesn't build my typescript or need to know anything about it.
So maybe this is an issue to request that if RtBypassTypeScriptCompilation=true
, then cater for not finding or having anything to do with my tsconfig.json file?
Reinforced.Typings.settings.xml : warning : TypeScript sources will not be built before project compile because it is disabled by Reinforced.Typings configuration [C: \code\src\Web.Site\Web.Site.csproj]
RT is fixing build tasks
RT has fixed build tasks:ResolveReferences;ResolveKeySource;SetWin32ManifestProperties;_GenerateCompileInputs;BeforeCompile;_TimeStampBeforeCompile;CoreCompile;_TimeStampAfterCompile;AfterCompile;;_AfterCompileWinFXInternal
C:\code\packages\Reinforced.Typings.1.3.0\build\Reinforced.Typings.targets(58,3): error MSB4044: The "RemoveTypeScriptStep" task was not given a value for the
required parameter "Original". [C:\code\src\Web.Site\Web.Site.csproj]
It seems OK for us to rely on this default behavior so I would like to not see warnings for it.
Perhaps we could either 1) have a config item for suppressing all Typings WARNINGS or 2) particular warnings could be suppressed - in this case "RTW0003_TypeUnknown"
Sorry. User error :)
Is it possible to run Reinforced.Typings over multiple projects? If so, could you share a snippet on how to go about doing so?
Hello!
I have a .csproj with circa 250 C# files (a mix of classes, interfaces and enums). I was able to successfully run your translator tool for interfaces and enums, but when including all the classes then I get the error from the title:
packages\Reinforced.Typings.1.3.7\build\Reinforced.Typings.targets(76,3): error MSB6006: "rtcli.exe" exited with code -1073741571.
Could you please help me out on how to narrow down the issue, so I could potentially locate the problematic class and see what's bugging the translator tool or even better is this a sort of a common issue for which you can help me out?
Currently I am narrowing it down by filtering on namespaces as when I cherry pick some classes the translation is successful.
I'm using a custom configure method per instructions on wiki, like this:
public static void Configure(ConfigurationBuilder builder)
{
// "TranslationConfiguration" below, is the name of this static class which has this method, and
// which is in the assembly that holds all the view models
var asm = Assembly.GetAssembly(typeof(TranslationConfiguration));
var viewModelTypes = asm.GetTypes();
var classes = new List<Type>();
var interfaces = new List<Type>();
var enums = new List<Type>();
foreach (var t in viewModelTypes)
{
if (t.IsClass) classes.Add(t);
else if (t.IsInterface) interfaces.Add(t);
else if (t.IsEnum) enums.Add(t);
}
var classesConfig = new Action<IClassConfigurationBuilder>(c => c.WithAllProperties());
var intfConfig = new Action<IInterfaceConfigurationBuilder>(c =>
{
c.WithAllFields();
c.WithAllProperties();
c.AutoI(false);
});
builder.ExportAsClasses(classes, classesConfig);
builder.ExportAsInterfaces(interfaces, intfConfig);
builder.ExportAsEnums(enums);
}
Hope you can advise me how to debug the rtcli or any ideas would be welcome, thanks.
Thanks for making this great tool.
V.
Hi,
Is it possible to generate class from enum without creating specific Code Generator?
I have an c# enum of this kind:
public enum MyEnum { [EnumMember(Value = "Value1")] Member1, [EnumMember(Value = "Value2")] Member2, [EnumMember(Value = "Value3")] Member3, }
I want to have something like this in TypeScript:
export class MyClass { Member1 = "Value1"; Member2 = "Value2"; Member3 = "Value3"; }
Started getting this error last week after I made a lot of changes to my project. Not sure where to begin looking to fix the problem, but thought I might get a head start on tomorrow if I go ahead and post here.
Anything I can do to help debug this situation?
I'm using Reinforced.Typing version 1.3.1.
For the case when models are stored within Console Application, that assembly won't be resolved correctly inside CurrentDomainOnAssemblyResolve
method.
Actually referenced console assembly will be stored inside Bootstrapper
's _referencesCache
, but LookupAssemblyPath
method will fail to find it. Because it will be looking for {assemblyName}.dll
but not for {assemblyName}.exe
. '.dll' extension is added to assembly name just before the call.
Line that adds .dll
:
Log and relevant stack-trace:
Reinforced.Typings CLI generator (c) 2015 by Pavel B. Novikov
Reinforced.Typings : Build warning RT0099: Unrecognized parameter: References
Looking up for assembly D:\dev\example\GraphicsTypescript\obj\Debug\GraphicsTypescript.dll
Already have full path to assembly D:\dev\example\GraphicsTypescript\obj\Debug\GraphicsTypescript.dll
Looking up for assembly Example.dll
Reinforced.Typings : Build warning RT0099: Assembly Example.dll may be resolved incorrectly
Reinforced.Typings : Unexpected error RT0999: Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Reinforced.Typings.Cli.Bootstrapper.<>c__DisplayClass8_0.<ResolveFluentMethod>b__0(ConfigurationBuilder builder) in D:\dev\Reinforced.Typings\Reinforced.Typings.Cli\Bootstrapper.cs:line 105
at Reinforced.Typings.TsExporter.Initialize() in D:\dev\Reinforced.Typings\Reinforced.Typings\TsExporter.cs:line 83
at Reinforced.Typings.TsExporter.Export() in D:\dev\Reinforced.Typings\Reinforced.Typings\TsExporter.cs:line 180
at Reinforced.Typings.Cli.Bootstrapper.Main(String[] args) in D:\dev\Reinforced.Typings\Reinforced.Typings.Cli\Bootstrapper.cs:line 48
Example
is an .exe
not .dll
.
That was somewhat mentioned in #5.
Is it possible to write C# code to generate TypeScript type guards?
My case if the following:
export interface IBaseClass
{
Id: number;
Name: string;
}
export interface IFirstClass extends IBaseClass
{
SomeProperty: number;
}
export interface ISecondClass extends IBaseClass
{
SomeOtherProperty: string;
}
and wanting to use it in a method like
doStuff(value: IBaseClass): void
{
if (value is IFirstClass) {
//Do something with value.SomeProperty
}
}
I know that in order to do this, I need some type guarding code like this:
export function isFirstClass(item: IFirstClass | ISecondClass): item is IFirstClass {
return (<IFirstClass>item).SomeProperty !== undefined;
}
Writing it, is not a big deal as such, but I wanted to know if there are any built in options to generate this so I don't have to maintain it manually when the file is updated?
Hi, I just wanted your advice on whether I should create a new project or modify this one.
I'm thinking about using this project code-base to detect Json.NET attributes that we already have on our C# code for deserializing objects into JSON - as well.
So, my idea is to have a configuration option to look for [JsonObject] and [JsonProperty] etc as well as [TsInterface] and [TsProperty].
Because, many of our [TsInterface] attributes are just duplicating the attributes we have already setup using [JsonObject]
But I'm interested in your opinion... do you think this idea would be better as a separate project or as some kind of config/option in this one?
Using the fluent configuration.
public static void Configure(ConfigurationBuilder builder)
{
builder.ExportAsEnum<MyNamespace.MyEnum>()
.DontIncludeToNamespace();
builder.ExportAsInterface<MyNamespace.MyModel>()
.DontIncludeToNamespace();
}
results in
declare module MyNamespace {
export enum MyEnum {
Foo = 0,
Bar = 1,
}
}
interface IMyModel
{
}
Sorry for this silly issue which actually leads to the real issue... but I can not tag my question on StackOverfow with "reinforced-typings" due to having less then 1500 reputation. :)
So here is the link to it: https://stackoverflow.com/questions/47220861/upgrading-reinforced-typings-to-1-4-0-from-1-3-7-crashes-build
TsProperty(ShouldBeCamelCased=false
) property only works half-way ;-)
I gather if you set it to true, then it will override the default config settings of false - this is what it claims to do but I have no need for this
But I do want it to do the opposite... and it will not
eg the below example, still outputs "originalName" camel cased - even though I've explicitly set it to not camel case - where my settings are CamelCase by default
[TsProperty(ShouldBeCamelCased = false)]
public virtual string OriginalName { get; set; }
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.