From 372a89807c7ebcdab9690ef753dd02c2e6fa5dff Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Thu, 16 Nov 2023 10:57:03 -0300 Subject: [PATCH] TypeScript: fixes ToJSON return type. Regression from 01615aff2129bc4fe9d58f5c597c6046c2d2f22f --- package.json | 2 +- src/types/HelperTypes.ts | 8 +++++--- test/TypeScriptTypes.test.ts | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b7ba2e91..3444541e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@colyseus/schema", - "version": "2.0.23", + "version": "2.0.24", "description": "Binary state serializer with delta encoding for games", "bin": { "schema-codegen": "./bin/schema-codegen" diff --git a/src/types/HelperTypes.ts b/src/types/HelperTypes.ts index 0d94a46c..3c3908ef 100644 --- a/src/types/HelperTypes.ts +++ b/src/types/HelperTypes.ts @@ -12,7 +12,9 @@ export type NonFunctionPropNames = { export type ToJSON = NonFunctionProps<{ [K in keyof T]: T[K] extends MapSchema ? Record - : T[K] extends ArraySchema - ? U[] - : T[K] + : T[K] extends Map + ? Record + : T[K] extends ArraySchema + ? U[] + : T[K] }>; \ No newline at end of file diff --git a/test/TypeScriptTypes.test.ts b/test/TypeScriptTypes.test.ts index c6165b4a..15132b12 100644 --- a/test/TypeScriptTypes.test.ts +++ b/test/TypeScriptTypes.test.ts @@ -16,6 +16,30 @@ describe("TypeScript Types", () => { orderPriority: null, })); state.encodeAll(); - console.log("DONE!"); + assert.ok(true); }); + + describe("complex declaration scenarios", () => { + it("implements / extends without conflicts", () => { + // Defines a generic schema + interface SchemaInterface extends Schema { + players: Map; + items: string[]; + } + + // Implements the above interface + // MapSchema is compatible with Map + class SchemaInterfaceImpl extends Schema implements SchemaInterface { + players: MapSchema; + items: ArraySchema; + } + + // Uses the schema interface + abstract class AbstractRoom { } + + // Uses the schema implementation + class AbstractRoomImpl extends AbstractRoom { } + }); + + }) }); \ No newline at end of file