From c40be646af9cc3ee04ffaf44ee84afb5ff8e7d8f Mon Sep 17 00:00:00 2001 From: Den Mukhametianov Date: Thu, 7 Mar 2019 19:59:27 +0500 Subject: [PATCH 1/7] Substitute value in enums where getter returns constant value --- .../SimpleGenerator/enum-types.expected.ts | 2 ++ .../Types/EnumContainingRootType.cs | 2 ++ .../CustomTypeTypeBuildingContext.cs | 26 ++++++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.ts b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.ts index f1a5568..beaf310 100644 --- a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.ts +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.ts @@ -3,6 +3,8 @@ export type EnumContainingRootType = { defaultEnum: DefaultEnum; nullableEnum?: null | DefaultEnum; explicitEnum: ExplicitEnum; + defaultEnumWithConstGetter: 'A'; + explicitEnumWithConstGetter: 'C'; }; export type DefaultEnum = 'A' | 'B'; export const DefaultEnums = { diff --git a/TypeScript.ContractGenerator.Tests/Types/EnumContainingRootType.cs b/TypeScript.ContractGenerator.Tests/Types/EnumContainingRootType.cs index d836e1f..becaf21 100644 --- a/TypeScript.ContractGenerator.Tests/Types/EnumContainingRootType.cs +++ b/TypeScript.ContractGenerator.Tests/Types/EnumContainingRootType.cs @@ -5,6 +5,8 @@ public class EnumContainingRootType public DefaultEnum DefaultEnum { get; set; } public DefaultEnum? NullableEnum { get; set; } public ExplicitEnum ExplicitEnum { get; set; } + public DefaultEnum DefaultEnumWithConstGetter => DefaultEnum.A; + public ExplicitEnum ExplicitEnumWithConstGetter => ExplicitEnum.C; } public enum DefaultEnum diff --git a/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs b/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs index 843d526..a85aed9 100644 --- a/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs +++ b/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Reflection; +using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using JetBrains.Annotations; @@ -55,12 +56,25 @@ protected virtual TypeScriptTypeDefintion CreateComplexTypeScriptDefinition(ITyp { var (isNullable, type) = TypeScriptGeneratorHelpers.ProcessNullable(property, property.PropertyType); - result.Members.Add(new TypeScriptTypeMemberDeclaration - { - Name = BuildPropertyName(property.Name), - Optional = isNullable && options.EnableOptionalProperties, - Type = GetMaybeNullableComplexType(typeGenerator, type, property, isNullable), - }); + if(property.PropertyType.IsEnum && !property.GetMethod.GetCustomAttributes().Any()) + { + var value = property.GetMethod.Invoke(Activator.CreateInstance(Type), null); + result.Members.Add(new TypeScriptTypeMemberDeclaration + { + Name = BuildPropertyName(property.Name), + Optional = isNullable && options.EnableOptionalProperties, + Type = new TypeScriptStringLiteralType(value.ToString()), + }); + } + else + { + result.Members.Add(new TypeScriptTypeMemberDeclaration + { + Name = BuildPropertyName(property.Name), + Optional = isNullable && options.EnableOptionalProperties, + Type = GetMaybeNullableComplexType(typeGenerator, type, property, isNullable), + }); + } } return result; } From 1534c269aaaf859ada332cdf1eb634050936905e Mon Sep 17 00:00:00 2001 From: Den Mukhametianov Date: Fri, 8 Mar 2019 21:57:03 +0500 Subject: [PATCH 2/7] Flow tests fix --- .../Files/SimpleGenerator/enum-types.expected.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.js b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.js index 7f1ebc4..3413d7e 100644 --- a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.js +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.js @@ -3,6 +3,8 @@ export type EnumContainingRootType = { defaultEnum: DefaultEnum; nullableEnum?: null | DefaultEnum; explicitEnum: ExplicitEnum; + defaultEnumWithConstGetter: 'A'; + explicitEnumWithConstGetter: 'C'; }; export type DefaultEnum = 'A' | 'B'; export const DefaultEnums = { From 9caaa5f0f2b3b7d2dfe3d06b86993926803a3af6 Mon Sep 17 00:00:00 2001 From: Den Mukhametianov Date: Fri, 8 Mar 2019 22:05:19 +0500 Subject: [PATCH 3/7] Review fixes: check if there is default constructor, check CanWrite instead of CompilerGeneratedAttribute presence --- .../CustomTypeTypeBuildingContext.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs b/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs index a85aed9..58145e7 100644 --- a/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs +++ b/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs @@ -56,14 +56,13 @@ protected virtual TypeScriptTypeDefintion CreateComplexTypeScriptDefinition(ITyp { var (isNullable, type) = TypeScriptGeneratorHelpers.ProcessNullable(property, property.PropertyType); - if(property.PropertyType.IsEnum && !property.GetMethod.GetCustomAttributes().Any()) + if(TryGetGetOnlyEnumPropertyValue(property, out var value)) { - var value = property.GetMethod.Invoke(Activator.CreateInstance(Type), null); result.Members.Add(new TypeScriptTypeMemberDeclaration { Name = BuildPropertyName(property.Name), Optional = isNullable && options.EnableOptionalProperties, - Type = new TypeScriptStringLiteralType(value.ToString()), + Type = new TypeScriptStringLiteralType(value), }); } else @@ -79,6 +78,17 @@ protected virtual TypeScriptTypeDefintion CreateComplexTypeScriptDefinition(ITyp return result; } + private bool TryGetGetOnlyEnumPropertyValue(PropertyInfo property, out string value) + { + if(!property.PropertyType.IsEnum || property.CanWrite || Type.GetConstructors().All(x => x.GetParameters().Length > 0)) + { + value = null; + return false; + } + value = property.GetMethod.Invoke(Activator.CreateInstance(Type), null).ToString(); + return true; + } + private TypeScriptType GetMaybeNullableComplexType(ITypeGenerator typeGenerator, Type type, PropertyInfo property, bool isNullable) { var propertyType = typeGenerator.BuildAndImportType(Unit, null, type); From 23cdf128c7793b634b9caa1c013aa7685adad407 Mon Sep 17 00:00:00 2001 From: Den Mukhametianov Date: Fri, 8 Mar 2019 22:58:38 +0500 Subject: [PATCH 4/7] Support TypeScriptEnum in const getters --- .../EndToEndTests.cs | 9 +++++++++ ...ith-const-getter-fixed-strings.expected.js | 5 +++++ ...ith-const-getter-fixed-strings.expected.ts | 5 +++++ ...h-const-getter-typescript-enum.expected.js | 13 +++++++++++++ ...h-const-getter-typescript-enum.expected.ts | 13 +++++++++++++ .../SimpleGenerator/enum-types.expected.js | 2 -- .../SimpleGenerator/enum-types.expected.ts | 2 -- .../TypeScript.ContractGenerator.Tests.csproj | 6 +++++- .../Types/EnumContainingRootType.cs | 8 ++++++-- .../CodeDom/TypeScriptEnumValueType.cs | 19 +++++++++++++++++++ .../CodeDom/TypeScriptExpressionType.cs | 17 +++++++++++++++++ .../CustomTypeTypeBuildingContext.cs | 15 ++++++++++++++- 12 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-fixed-strings.expected.js create mode 100644 TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-fixed-strings.expected.ts create mode 100644 TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-typescript-enum.expected.js create mode 100644 TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-typescript-enum.expected.ts create mode 100644 TypeScript.ContractGenerator/CodeDom/TypeScriptEnumValueType.cs create mode 100644 TypeScript.ContractGenerator/CodeDom/TypeScriptExpressionType.cs diff --git a/TypeScript.ContractGenerator.Tests/EndToEndTests.cs b/TypeScript.ContractGenerator.Tests/EndToEndTests.cs index 85c1b3f..8b8bb9a 100644 --- a/TypeScript.ContractGenerator.Tests/EndToEndTests.cs +++ b/TypeScript.ContractGenerator.Tests/EndToEndTests.cs @@ -34,6 +34,15 @@ public void GenerateCodeTest(Type rootType, string expectedFileName) generatedCode.Should().Be(expectedCode); } + [TestCase(EnumGenerationMode.FixedStringsAndDictionary, "enum-types-with-const-getter-fixed-strings.expected")] + [TestCase(EnumGenerationMode.TypeScriptEnum, "enum-types-with-const-getter-typescript-enum.expected")] + public void GenerateEnumWithConstGetterTest(EnumGenerationMode enumGenerationMode, string expectedFileName) + { + var generatedCode = GenerateCode(new TypeScriptGenerationOptions {EnumGenerationMode = enumGenerationMode}, CustomTypeGenerator.Null, typeof(EnumWithConstGetterContainingRootType)).Single().Replace("\r\n", "\n"); + var expectedCode = GetExpectedCode($"SimpleGenerator/{expectedFileName}"); + generatedCode.Should().Be(expectedCode); + } + [TestCase(typeof(FlatTypeLocator))] [TestCase(typeof(SimpleStructureTypeLocator))] public void GenerateFilesTest(Type type) diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-fixed-strings.expected.js b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-fixed-strings.expected.js new file mode 100644 index 0000000..4283670 --- /dev/null +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-fixed-strings.expected.js @@ -0,0 +1,5 @@ + +export type EnumWithConstGetterContainingRootType = { + defaultEnum: 'A'; + explicitEnum: 'C'; +}; diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-fixed-strings.expected.ts b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-fixed-strings.expected.ts new file mode 100644 index 0000000..4283670 --- /dev/null +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-fixed-strings.expected.ts @@ -0,0 +1,5 @@ + +export type EnumWithConstGetterContainingRootType = { + defaultEnum: 'A'; + explicitEnum: 'C'; +}; diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-typescript-enum.expected.js b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-typescript-enum.expected.js new file mode 100644 index 0000000..f19c64c --- /dev/null +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-typescript-enum.expected.js @@ -0,0 +1,13 @@ + +export type EnumWithConstGetterContainingRootType = { + defaultEnum: DefaultEnum.A; + explicitEnum: ExplicitEnum.C; +}; +export enum DefaultEnum { + A = 'A', + B = 'B', +} +export enum ExplicitEnum { + C = 'C', + D = 'D', +} diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-typescript-enum.expected.ts b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-typescript-enum.expected.ts new file mode 100644 index 0000000..f19c64c --- /dev/null +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types-with-const-getter-typescript-enum.expected.ts @@ -0,0 +1,13 @@ + +export type EnumWithConstGetterContainingRootType = { + defaultEnum: DefaultEnum.A; + explicitEnum: ExplicitEnum.C; +}; +export enum DefaultEnum { + A = 'A', + B = 'B', +} +export enum ExplicitEnum { + C = 'C', + D = 'D', +} diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.js b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.js index 3413d7e..7f1ebc4 100644 --- a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.js +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.js @@ -3,8 +3,6 @@ export type EnumContainingRootType = { defaultEnum: DefaultEnum; nullableEnum?: null | DefaultEnum; explicitEnum: ExplicitEnum; - defaultEnumWithConstGetter: 'A'; - explicitEnumWithConstGetter: 'C'; }; export type DefaultEnum = 'A' | 'B'; export const DefaultEnums = { diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.ts b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.ts index beaf310..f1a5568 100644 --- a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.ts +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/enum-types.expected.ts @@ -3,8 +3,6 @@ export type EnumContainingRootType = { defaultEnum: DefaultEnum; nullableEnum?: null | DefaultEnum; explicitEnum: ExplicitEnum; - defaultEnumWithConstGetter: 'A'; - explicitEnumWithConstGetter: 'C'; }; export type DefaultEnum = 'A' | 'B'; export const DefaultEnums = { diff --git a/TypeScript.ContractGenerator.Tests/TypeScript.ContractGenerator.Tests.csproj b/TypeScript.ContractGenerator.Tests/TypeScript.ContractGenerator.Tests.csproj index 28f5882..8145875 100644 --- a/TypeScript.ContractGenerator.Tests/TypeScript.ContractGenerator.Tests.csproj +++ b/TypeScript.ContractGenerator.Tests/TypeScript.ContractGenerator.Tests.csproj @@ -1,4 +1,4 @@ - + false @@ -55,6 +55,10 @@ + + + + diff --git a/TypeScript.ContractGenerator.Tests/Types/EnumContainingRootType.cs b/TypeScript.ContractGenerator.Tests/Types/EnumContainingRootType.cs index becaf21..612858a 100644 --- a/TypeScript.ContractGenerator.Tests/Types/EnumContainingRootType.cs +++ b/TypeScript.ContractGenerator.Tests/Types/EnumContainingRootType.cs @@ -5,8 +5,12 @@ public class EnumContainingRootType public DefaultEnum DefaultEnum { get; set; } public DefaultEnum? NullableEnum { get; set; } public ExplicitEnum ExplicitEnum { get; set; } - public DefaultEnum DefaultEnumWithConstGetter => DefaultEnum.A; - public ExplicitEnum ExplicitEnumWithConstGetter => ExplicitEnum.C; + } + + public class EnumWithConstGetterContainingRootType + { + public DefaultEnum DefaultEnum => DefaultEnum.A; + public ExplicitEnum ExplicitEnum => ExplicitEnum.C; } public enum DefaultEnum diff --git a/TypeScript.ContractGenerator/CodeDom/TypeScriptEnumValueType.cs b/TypeScript.ContractGenerator/CodeDom/TypeScriptEnumValueType.cs new file mode 100644 index 0000000..275d770 --- /dev/null +++ b/TypeScript.ContractGenerator/CodeDom/TypeScriptEnumValueType.cs @@ -0,0 +1,19 @@ +namespace SkbKontur.TypeScript.ContractGenerator.CodeDom +{ + public class TypeScriptEnumValueType : TypeScriptType + { + public TypeScriptEnumValueType(TypeScriptType enumType, string value) + { + this.enumType = enumType; + this.value = value; + } + + public override string GenerateCode(ICodeGenerationContext context) + { + return $"{enumType.GenerateCode(context)}.{value}"; + } + + private readonly TypeScriptType enumType; + private readonly string value; + } +} \ No newline at end of file diff --git a/TypeScript.ContractGenerator/CodeDom/TypeScriptExpressionType.cs b/TypeScript.ContractGenerator/CodeDom/TypeScriptExpressionType.cs new file mode 100644 index 0000000..3036154 --- /dev/null +++ b/TypeScript.ContractGenerator/CodeDom/TypeScriptExpressionType.cs @@ -0,0 +1,17 @@ +namespace SkbKontur.TypeScript.ContractGenerator.CodeDom +{ + public class TypeScriptExpressionType : TypeScriptType + { + public TypeScriptExpressionType(TypeScriptExpression expression) + { + Expression = expression; + } + + public TypeScriptExpression Expression { get; } + + public override string GenerateCode(ICodeGenerationContext context) + { + return Expression.GenerateCode(context); + } + } +} \ No newline at end of file diff --git a/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs b/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs index 58145e7..7f5dcff 100644 --- a/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs +++ b/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs @@ -62,7 +62,7 @@ protected virtual TypeScriptTypeDefintion CreateComplexTypeScriptDefinition(ITyp { Name = BuildPropertyName(property.Name), Optional = isNullable && options.EnableOptionalProperties, - Type = new TypeScriptStringLiteralType(value), + Type = GetConstEnumType(typeGenerator, property, value), }); } else @@ -78,6 +78,19 @@ protected virtual TypeScriptTypeDefintion CreateComplexTypeScriptDefinition(ITyp return result; } + private TypeScriptType GetConstEnumType(ITypeGenerator typeGenerator, PropertyInfo property, string value) + { + switch(options.EnumGenerationMode) { + case EnumGenerationMode.FixedStringsAndDictionary: + return new TypeScriptStringLiteralType(value); + case EnumGenerationMode.TypeScriptEnum: + return new TypeScriptEnumValueType(typeGenerator.BuildAndImportType(Unit, property, property.PropertyType), value); + default: + throw new ArgumentOutOfRangeException(); + } + + } + private bool TryGetGetOnlyEnumPropertyValue(PropertyInfo property, out string value) { if(!property.PropertyType.IsEnum || property.CanWrite || Type.GetConstructors().All(x => x.GetParameters().Length > 0)) From f0ac6b4a66a15d0c66005135650e5fae3713b15a Mon Sep 17 00:00:00 2001 From: Den Mukhametianov Date: Fri, 8 Mar 2019 23:20:28 +0500 Subject: [PATCH 5/7] Remove redundant file --- .../CodeDom/TypeScriptExpressionType.cs | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 TypeScript.ContractGenerator/CodeDom/TypeScriptExpressionType.cs diff --git a/TypeScript.ContractGenerator/CodeDom/TypeScriptExpressionType.cs b/TypeScript.ContractGenerator/CodeDom/TypeScriptExpressionType.cs deleted file mode 100644 index 3036154..0000000 --- a/TypeScript.ContractGenerator/CodeDom/TypeScriptExpressionType.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace SkbKontur.TypeScript.ContractGenerator.CodeDom -{ - public class TypeScriptExpressionType : TypeScriptType - { - public TypeScriptExpressionType(TypeScriptExpression expression) - { - Expression = expression; - } - - public TypeScriptExpression Expression { get; } - - public override string GenerateCode(ICodeGenerationContext context) - { - return Expression.GenerateCode(context); - } - } -} \ No newline at end of file From b4ea113b354d4c734dd3315dbd4db4ccd8e97b3b Mon Sep 17 00:00:00 2001 From: Den Mukhametianov Date: Fri, 8 Mar 2019 23:20:32 +0500 Subject: [PATCH 6/7] reformat --- .../TypeBuilders/CustomTypeTypeBuildingContext.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs b/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs index 7f5dcff..1971986 100644 --- a/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs +++ b/TypeScript.ContractGenerator/TypeBuilders/CustomTypeTypeBuildingContext.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using System.Reflection; -using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using JetBrains.Annotations; @@ -35,7 +34,7 @@ private TypeScriptTypeDeclaration CreateComplexTypeScriptDeclarationWithoutDefin public override void Initialize(ITypeGenerator typeGenerator) { - if (Type.BaseType != typeof(object) && Type.BaseType != typeof(ValueType) && Type.BaseType != typeof(MarshalByRefObject) && Type.BaseType != null) + if(Type.BaseType != typeof(object) && Type.BaseType != typeof(ValueType) && Type.BaseType != typeof(MarshalByRefObject) && Type.BaseType != null) { typeGenerator.ResolveType(Type.BaseType); } @@ -52,7 +51,7 @@ protected virtual TypeScriptTypeDefintion CreateComplexTypeScriptDefinition(ITyp { var result = new TypeScriptTypeDefintion(); var properties = CreateTypeProperties(Type); - foreach (var property in properties) + foreach(var property in properties) { var (isNullable, type) = TypeScriptGeneratorHelpers.ProcessNullable(property, property.PropertyType); @@ -80,7 +79,8 @@ protected virtual TypeScriptTypeDefintion CreateComplexTypeScriptDefinition(ITyp private TypeScriptType GetConstEnumType(ITypeGenerator typeGenerator, PropertyInfo property, string value) { - switch(options.EnumGenerationMode) { + switch(options.EnumGenerationMode) + { case EnumGenerationMode.FixedStringsAndDictionary: return new TypeScriptStringLiteralType(value); case EnumGenerationMode.TypeScriptEnum: @@ -88,7 +88,6 @@ private TypeScriptType GetConstEnumType(ITypeGenerator typeGenerator, PropertyIn default: throw new ArgumentOutOfRangeException(); } - } private bool TryGetGetOnlyEnumPropertyValue(PropertyInfo property, out string value) @@ -106,13 +105,13 @@ private TypeScriptType GetMaybeNullableComplexType(ITypeGenerator typeGenerator, { var propertyType = typeGenerator.BuildAndImportType(Unit, null, type); - if (property.PropertyType.IsGenericParameter) + if(property.PropertyType.IsGenericParameter) return new TypeScriptTypeReference(property.PropertyType.Name); - if (isNullable && options.EnableExplicitNullability && !options.UseGlobalNullable) + if(isNullable && options.EnableExplicitNullability && !options.UseGlobalNullable) return new TypeScriptOrNullType(propertyType); - if (isNullable && options.EnableExplicitNullability && options.UseGlobalNullable) + if(isNullable && options.EnableExplicitNullability && options.UseGlobalNullable) return new TypeScriptNullableType(propertyType); return propertyType; From 8f4cfedeffcc82fe7c3464fe8874fc3ab9d72875 Mon Sep 17 00:00:00 2001 From: Den Mukhametianov Date: Fri, 8 Mar 2019 23:29:00 +0500 Subject: [PATCH 7/7] up version --- CHANGELOG.md | 5 +++++ version.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b3ab57..8cf2208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v1.4 - 2019.03.08 +- `//tslint:disable` is placed before codegen marker +- Global rename: `FlowType => TypeScript` +- Add support for enum properties with user-defined getter (see `GenerateEnumWithConstGetterTest` for details) + ## v1.3 - 2019.02.22 - Correctly generate built-in types - Add support for `List` and `Dictionary` diff --git a/version.json b/version.json index 07bb75a..50e008f 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.3", + "version": "1.4", "assemblyVersion": { "precision": "build" },