Skip to content

Commit 372a898

Browse files
committed
TypeScript: fixes ToJSON return type. Regression from 01615af
1 parent 3c510f7 commit 372a898

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@colyseus/schema",
3-
"version": "2.0.23",
3+
"version": "2.0.24",
44
"description": "Binary state serializer with delta encoding for games",
55
"bin": {
66
"schema-codegen": "./bin/schema-codegen"

src/types/HelperTypes.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export type NonFunctionPropNames<T> = {
1212
export type ToJSON<T> = NonFunctionProps<{
1313
[K in keyof T]: T[K] extends MapSchema<infer U>
1414
? Record<string, U>
15-
: T[K] extends ArraySchema<infer U>
16-
? U[]
17-
: T[K]
15+
: T[K] extends Map<string, infer U>
16+
? Record<string, U>
17+
: T[K] extends ArraySchema<infer U>
18+
? U[]
19+
: T[K]
1820
}>;

test/TypeScriptTypes.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ describe("TypeScript Types", () => {
1616
orderPriority: null,
1717
}));
1818
state.encodeAll();
19-
console.log("DONE!");
19+
assert.ok(true);
2020
});
21+
22+
describe("complex declaration scenarios", () => {
23+
it("implements / extends without conflicts", () => {
24+
// Defines a generic schema
25+
interface SchemaInterface extends Schema {
26+
players: Map<string, string>;
27+
items: string[];
28+
}
29+
30+
// Implements the above interface
31+
// MapSchema is compatible with Map
32+
class SchemaInterfaceImpl extends Schema implements SchemaInterface {
33+
players: MapSchema<string>;
34+
items: ArraySchema<string>;
35+
}
36+
37+
// Uses the schema interface
38+
abstract class AbstractRoom<T extends SchemaInterface> { }
39+
40+
// Uses the schema implementation
41+
class AbstractRoomImpl extends AbstractRoom<SchemaInterfaceImpl> { }
42+
});
43+
44+
})
2145
});

0 commit comments

Comments
 (0)