From 1824d75b3c910ab94311d7635db52370ea4987d0 Mon Sep 17 00:00:00 2001 From: Alexander Dobrynin Date: Wed, 27 Oct 2021 16:23:09 +0300 Subject: [PATCH 1/3] treat long type as number in javascript according to serializers' behavior (e.g. JSON.NET & Netwonsoft.JSON) --- .../TypeBuilders/BuiltinTypeBuildingContext.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TypeScript.ContractGenerator/TypeBuilders/BuiltinTypeBuildingContext.cs b/TypeScript.ContractGenerator/TypeBuilders/BuiltinTypeBuildingContext.cs index 899fe30..7052377 100644 --- a/TypeScript.ContractGenerator/TypeBuilders/BuiltinTypeBuildingContext.cs +++ b/TypeScript.ContractGenerator/TypeBuilders/BuiltinTypeBuildingContext.cs @@ -21,9 +21,9 @@ public static bool Accept(ITypeInfo type) protected override TypeScriptType ReferenceFromInternal(ITypeInfo type, TypeScriptUnit targetUnit, ITypeGenerator typeGenerator) { - if (builtinTypes.ContainsKey(type)) - return new TypeScriptBuildInType(builtinTypes[type]); - throw new ArgumentOutOfRangeException(); + if (builtinTypes.TryGetValue(type, out var typeScriptType)) + return new TypeScriptBuildInType(typeScriptType); + throw new ArgumentOutOfRangeException(nameof(type), $"Type '{type}' is not found"); } private static readonly Dictionary builtinTypes = new Dictionary @@ -41,8 +41,8 @@ protected override TypeScriptType ReferenceFromInternal(ITypeInfo type, TypeScri {TypeInfo.From(), "(Date | string)"}, {TypeInfo.From(), "(number | string)"}, {TypeInfo.From(), "string"}, - {TypeInfo.From(), "string"}, - {TypeInfo.From(), "string"}, + {TypeInfo.From(), "number"}, + {TypeInfo.From(), "number"}, {TypeInfo.From(), "string"}, {TypeInfo.From(), "string"}, {TypeInfo.From(), "string"}, From 167c4c4d6077576e678b9b9a562d38d7cbe3b4ce Mon Sep 17 00:00:00 2001 From: Alexander Dobrynin Date: Wed, 27 Oct 2021 16:33:36 +0300 Subject: [PATCH 2/3] use latest feature version of dotnet sdk --- global.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/global.json b/global.json index d58cbe0..b86006c 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,6 @@ { "sdk": { - "version": "5.0.302" + "version": "5.0.302", + "rollForward": "latestFeature" } } \ No newline at end of file From 07b72ec3a941b036c3301179337d3f167c659304 Mon Sep 17 00:00:00 2001 From: Alexander Dobrynin Date: Wed, 27 Oct 2021 18:59:21 +0300 Subject: [PATCH 3/3] tests expect long to be generated as number --- .../Files/CustomGenerator/nullable-types.ts | 4 ++-- .../Files/CustomGenerator/simple-types.ts | 4 ++-- .../Files/SimpleGenerator/nullable-types.ts | 4 ++-- .../Files/SimpleGenerator/simple-types.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/TypeScript.ContractGenerator.Tests/Files/CustomGenerator/nullable-types.ts b/TypeScript.ContractGenerator.Tests/Files/CustomGenerator/nullable-types.ts index 5dcf874..56de267 100644 --- a/TypeScript.ContractGenerator.Tests/Files/CustomGenerator/nullable-types.ts +++ b/TypeScript.ContractGenerator.Tests/Files/CustomGenerator/nullable-types.ts @@ -1,7 +1,7 @@ export type SimpleNullableRootType = { - long?: null | string; - uLong?: null | string; + long?: null | number; + uLong?: null | number; int?: null | number; uInt?: null | number; short?: null | number; diff --git a/TypeScript.ContractGenerator.Tests/Files/CustomGenerator/simple-types.ts b/TypeScript.ContractGenerator.Tests/Files/CustomGenerator/simple-types.ts index a96c587..6777eb3 100644 --- a/TypeScript.ContractGenerator.Tests/Files/CustomGenerator/simple-types.ts +++ b/TypeScript.ContractGenerator.Tests/Files/CustomGenerator/simple-types.ts @@ -1,7 +1,7 @@ export type SimpleRootType = { - long: string; - uLong: string; + long: number; + uLong: number; int: number; uInt: number; short: number; diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/nullable-types.ts b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/nullable-types.ts index 410f15b..d3da815 100644 --- a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/nullable-types.ts +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/nullable-types.ts @@ -1,7 +1,7 @@ export type SimpleNullableRootType = { - long?: null | string; - uLong?: null | string; + long?: null | number; + uLong?: null | number; int?: null | number; uInt?: null | number; short?: null | number; diff --git a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/simple-types.ts b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/simple-types.ts index 3adfedb..8cae4e1 100644 --- a/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/simple-types.ts +++ b/TypeScript.ContractGenerator.Tests/Files/SimpleGenerator/simple-types.ts @@ -1,7 +1,7 @@ export type SimpleRootType = { - long: string; - uLong: string; + long: number; + uLong: number; int: number; uInt: number; short: number;