From 58e00a9ca3f47556a443266e751baf772da9d547 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Mon, 14 Feb 2022 00:58:05 +0000 Subject: [PATCH] Improving strict typescript checking --- lib/jrpc.js | 5 +++++ package.json | 2 +- src/targets/typescript.ts | 1 + templates/ts_service_client.ts | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/jrpc.js b/lib/jrpc.js index 3b42786..b6012bb 100755 --- a/lib/jrpc.js +++ b/lib/jrpc.js @@ -10353,6 +10353,7 @@ var TypescriptTarget = class extends CompileTarget { } a(2, ``); a(2, `p.push(ctx);`); + a(2, `//@ts-ignore This will cause a typescript error when strict checking, since p is not a tuple`); a(2, `return this.${fnc.name}.call(this, ...p)` + (fnc.return ? `.then(${((_a = fnc.return) == null ? void 0 : _a.array) ? `res => res.map(e => apply_${fnc.return.type}(e))` : `res => apply_${fnc.return.type}(res)`});` : "")); a(1, `}`); a(0, ``); @@ -10517,10 +10518,12 @@ var CSharpTarget = class extends CompileTarget { } t.forEach((l) => lines.push(" ".repeat(i) + l.trim())); }; + a(0, `using System;`); a(0, `using System.Text.Json;`); a(0, `using System.Text.Json.Serialization;`); a(0, `using System.Text.Json.Nodes;`); a(0, `using System.Threading.Tasks;`); + a(0, `using System.Collections.Generic;`); a(0, ``); a(0, `namespace ${this.namespace};`); a(0, ``); @@ -10573,10 +10576,12 @@ var CSharpTarget = class extends CompileTarget { } t.forEach((l) => lines.push(" ".repeat(i) + l.trim())); }; + a(0, `using System;`); a(0, `using System.Text.Json;`); a(0, `using System.Text.Json.Serialization;`); a(0, `using System.Text.Json.Nodes;`); a(0, `using System.Threading.Tasks;`); + a(0, `using System.Collections.Generic;`); a(0, ``); a(0, `namespace ${this.namespace};`); a(0, ``); diff --git a/package.json b/package.json index 45e36df..8696d0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/jrpcgen", - "version": "1.0.28", + "version": "1.0.29", "main": "lib/index.js", "license": "MIT", "packageManager": "yarn@3.1.1", diff --git a/src/targets/typescript.ts b/src/targets/typescript.ts index 7b9b96e..6a903a5 100644 --- a/src/targets/typescript.ts +++ b/src/targets/typescript.ts @@ -383,6 +383,7 @@ export class TypescriptTarget extends CompileTarget { a(2, ``); a(2, `p.push(ctx);`); + a(2, `//@ts-ignore This will cause a typescript error when strict checking, since p is not a tuple`) a( 2, `return this.${fnc.name}.call(this, ...p)` + //TODO: Refactor. This line is way to compicated for anyone to understand, including me diff --git a/templates/ts_service_client.ts b/templates/ts_service_client.ts index 296897f..17abdd1 100644 --- a/templates/ts_service_client.ts +++ b/templates/ts_service_client.ts @@ -22,7 +22,7 @@ export class Service { export class ServiceProvider { services = new Map(); - requests = new Map(); + requests = new Map(); constructor(private sendPacket: IMessageCallback) {}