Skip to content

Commit

Permalink
fix ArraySchema#filter() return type. fixes #172
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed May 5, 2024
1 parent ce9bdd5 commit 36c6aeb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@colyseus/schema",
"version": "2.0.31",
"version": "2.0.32",
"description": "Binary state serializer with delta encoding for games",
"bin": {
"schema-codegen": "./bin/schema-codegen"
Expand Down
6 changes: 3 additions & 3 deletions src/types/ArraySchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ export class ArraySchema<V = any> implements Array<V>, SchemaDecoderCallbacks {
//
// FIXME: this should be O(1)
//

index = Math.trunc(index) || 0;
// Allow negative indexing from the end
if (index < 0) index += this.length;
// OOB access is guaranteed to return undefined
if (index < 0 || index >= this.length) return undefined;

const key = Array.from(this.$items.keys())[index];
return this.$items.get(key);
}
Expand Down Expand Up @@ -434,7 +434,7 @@ export class ArraySchema<V = any> implements Array<V>, SchemaDecoderCallbacks {
* @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
filter(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any)
filter(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): V[]
filter<S extends V>(callbackfn: (value: V, index: number, array: V[]) => value is S, thisArg?: any): V[] {
return Array.from(this.$items.values()).filter(callbackfn, thisArg);
}
Expand Down

0 comments on commit 36c6aeb

Please sign in to comment.