Skip to content

Commit a47e3e5

Browse files
committed
plain schema({}): fix type inference collections of primitive types
1 parent 3dd71cb commit a47e3e5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
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": "3.0.74",
3+
"version": "3.0.75",
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,24 @@ export type InferValueType<T extends DefinitionType> =
3939

4040
// Handle direct array patterns
4141
: T extends Array<infer ChildType extends Constructor> ? InstanceType<ChildType>[]
42+
: T extends Array<infer ChildType extends RawPrimitiveType> ? InferValueType<ChildType>[] // primitive types
4243
: T extends Array<infer ChildType> ? (ChildType extends Record<string | number, string | number> ? ChildType[keyof ChildType][] : ChildType[]) // TS ENUM
4344

4445
// Handle collection object patterns
4546
: T extends { array: infer ChildType extends Constructor } ? InstanceType<ChildType>[]
47+
: T extends { array: infer ChildType extends RawPrimitiveType } ? InferValueType<ChildType>[] // primitive types
4648
: T extends { array: infer ChildType } ? (ChildType extends Record<string | number, string | number> ? ChildType[keyof ChildType][] : ChildType[]) // TS ENUM
4749

4850
: T extends { map: infer ChildType extends Constructor } ? MapSchema<InstanceType<ChildType>>
51+
: T extends { map: infer ChildType extends RawPrimitiveType } ? MapSchema<InferValueType<ChildType>> // primitive types
4952
: T extends { map: infer ChildType } ? (ChildType extends Record<string | number, string | number> ? MapSchema<ChildType[keyof ChildType]> : MapSchema<ChildType>) // TS ENUM
5053

5154
: T extends { set: infer ChildType extends Constructor } ? SetSchema<InstanceType<ChildType>>
55+
: T extends { set: infer ChildType extends RawPrimitiveType } ? SetSchema<InferValueType<ChildType>> // primitive types
5256
: T extends { set: infer ChildType } ? (ChildType extends Record<string | number, string | number> ? SetSchema<ChildType[keyof ChildType]> : SetSchema<ChildType>) // TS ENUM
5357

5458
: T extends { collection: infer ChildType extends Constructor } ? CollectionSchema<InstanceType<ChildType>>
59+
: T extends { collection: infer ChildType extends RawPrimitiveType } ? CollectionSchema<InferValueType<ChildType>> // primitive types
5560
: T extends { collection: infer ChildType } ? (ChildType extends Record<string | number, string | number> ? CollectionSchema<ChildType[keyof ChildType]> : CollectionSchema<ChildType>) // TS ENUM
5661

5762
// Handle direct types

0 commit comments

Comments
 (0)