Skip to content

Commit c662ecc

Browse files
committed
TypeScript: fixes .toJSON() return type.
1 parent 5cb5b06 commit c662ecc

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@colyseus/schema",
3-
"version": "2.0.16",
3+
"version": "2.0.17",
44
"description": "Binary state serializer with delta encoding for games",
55
"bin": {
66
"schema-codegen": "./bin/schema-codegen"
@@ -78,7 +78,7 @@
7878
"source-map-support": "^0.5.13",
7979
"ts-node": "^7.0.1",
8080
"tslib": "^2.1.0",
81-
"tsx": "^3.12.7",
81+
"tsx": "^3.13.0",
8282
"typescript": "^5.0.4"
8383
},
8484
"nyc": {

src/Schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,15 +898,15 @@ export abstract class Schema {
898898
const schema = this._definition.schema;
899899
const deprecated = this._definition.deprecated;
900900

901-
const obj: ToJSON<typeof this> = {};
901+
const obj: unknown = {};
902902
for (let field in schema) {
903903
if (!deprecated[field] && this[field] !== null && typeof (this[field]) !== "undefined") {
904904
obj[field] = (typeof (this[field]['toJSON']) === "function")
905905
? this[field]['toJSON']()
906906
: this[`_${field}`];
907907
}
908908
}
909-
return obj;
909+
return obj as ToJSON<typeof this>;
910910
}
911911

912912
discardAllChanges() {

src/types/HelperTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export type NonFunctionPropNames<T> = {
99
[K in keyof T]: T[K] extends Function ? never : K
1010
}[keyof T];
1111

12-
export type ToJSON<T> = Partial<NonFunctionProps<{
12+
export type ToJSON<T> = NonFunctionProps<{
1313
[K in keyof T]: T[K] extends MapSchema<infer U>
1414
? Record<string, U>
1515
: T[K] extends ArraySchema<infer U>
1616
? U[]
1717
: T[K]
18-
}>>;
18+
}>;

0 commit comments

Comments
 (0)