@colyseus/schema 4.0.16 → 4.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/schema",
3
- "version": "4.0.16",
3
+ "version": "4.0.18",
4
4
  "description": "Binary state serializer with delta encoding for games",
5
5
  "type": "module",
6
6
  "bin": {
package/src/Schema.ts CHANGED
@@ -122,7 +122,7 @@ export class Schema<C = any> implements IRef {
122
122
  * @param jsonData JSON data to restore the instance from
123
123
  * @returns
124
124
  */
125
- public restore(jsonData: ToJSON<this>): this {
125
+ public restore<T extends Partial<this>>(jsonData: ToJSON<T>): this {
126
126
  const metadata: Metadata = (this.constructor as typeof Schema)[Symbol.metadata];
127
127
 
128
128
  for (const fieldIndex in metadata) {
@@ -224,7 +224,7 @@ export class Schema<C = any> implements IRef {
224
224
  return cloned;
225
225
  }
226
226
 
227
- toJSON (this: any): ToJSON<this> {
227
+ toJSON (this: any): ToJSON<Partial<this>> {
228
228
  const obj: any = {};
229
229
  const metadata = this.constructor[Symbol.metadata];
230
230
  for (const index in metadata) {
@@ -129,7 +129,7 @@ export class StateCallbackStrategy<TState extends IRef> {
129
129
  /**
130
130
  * Listen to property changes on a nested instance.
131
131
  */
132
- listen<TInstance extends Schema, K extends PublicPropNames<TInstance>>(
132
+ listen<TInstance, K extends PublicPropNames<TInstance>>(
133
133
  instance: TInstance,
134
134
  property: K,
135
135
  handler: PropertyChangeCallback<TInstance[K]>,