diff --git a/packages/struct/src/basic/definition.ts b/packages/struct/src/basic/definition.ts index d5881b09..7861642a 100644 --- a/packages/struct/src/basic/definition.ts +++ b/packages/struct/src/basic/definition.ts @@ -21,7 +21,7 @@ import type { StructValue } from './struct-value'; export abstract class StructFieldDefinition< TOptions = void, TValue = unknown, - TOmitInitKey = never, + TOmitInitKey extends PropertyKey = never, > { public readonly options: TOptions; diff --git a/packages/struct/src/struct.ts b/packages/struct/src/struct.ts index e7e0f2c9..3dc08c6c 100644 --- a/packages/struct/src/struct.ts +++ b/packages/struct/src/struct.ts @@ -1,6 +1,6 @@ import { StructDefaultOptions, StructDeserializationContext, StructFieldDefinition, StructFieldValue, StructOptions, StructSerializationContext, StructValue } from './basic'; -import { ArrayBufferFieldType, ArrayBufferLikeFieldType, FixedLengthArrayBufferLikeFieldDefinition, FixedLengthArrayBufferLikeFieldOptions, NumberFieldDefinition, NumberFieldType, StringFieldType, Uint8ClampedArrayFieldType, VariableLengthArrayBufferLikeFieldDefinition, VariableLengthArrayBufferLikeFieldOptions } from './types'; -import { Awaited, Evaluate, Identity, KeysOfType, Overwrite } from './utils'; +import { ArrayBufferFieldType, ArrayBufferLikeFieldType, FixedLengthArrayBufferLikeFieldDefinition, FixedLengthArrayBufferLikeFieldOptions, LengthField, NumberFieldDefinition, NumberFieldType, StringFieldType, Uint8ClampedArrayFieldType, VariableLengthArrayBufferLikeFieldDefinition, VariableLengthArrayBufferLikeFieldOptions } from './types'; +import { Awaited, Evaluate, Identity, Overwrite } from './utils'; export interface StructLike { deserialize(context: StructDeserializationContext): Promise; @@ -19,17 +19,18 @@ export type StructValueType> = */ type AddFieldDescriptor< TFields extends object, - TOmitInit extends string, + TOmitInitKey extends PropertyKey, TExtra extends object, TPostDeserialized, TFieldName extends PropertyKey, - TDefinition extends StructFieldDefinition> = + TDefinition extends StructFieldDefinition + > = Identity>, - // Merge two `TOmitInit - TOmitInit | TDefinition['omitInitKeyType'], + // Merge two `TOmitInitKey`s + TOmitInitKey | TDefinition['omitInitKeyType'], TExtra, TPostDeserialized >>; @@ -39,7 +40,7 @@ type AddFieldDescriptor< */ interface ArrayBufferLikeFieldCreator< TFields extends object, - TOmitInit extends string, + TOmitInitKey extends PropertyKey, TExtra extends object, TPostDeserialized > { @@ -63,7 +64,7 @@ interface ArrayBufferLikeFieldCreator< typescriptType?: TTypeScriptType, ): AddFieldDescriptor< TFields, - TOmitInit, + TOmitInitKey, TExtra, TPostDeserialized, TName, @@ -88,7 +89,7 @@ interface ArrayBufferLikeFieldCreator< typescriptType?: TTypeScriptType, ): AddFieldDescriptor< TFields, - TOmitInit, + TOmitInitKey, TExtra, TPostDeserialized, TName, @@ -104,7 +105,7 @@ interface ArrayBufferLikeFieldCreator< */ interface ArrayBufferTypeFieldDefinitionCreator< TFields extends object, - TOmitInit extends string, + TOmitInitKey extends PropertyKey, TExtra extends object, TPostDeserialized, TType extends ArrayBufferLikeFieldType @@ -118,7 +119,7 @@ interface ArrayBufferTypeFieldDefinitionCreator< typescriptType?: TTypeScriptType, ): AddFieldDescriptor< TFields, - TOmitInit, + TOmitInitKey, TExtra, TPostDeserialized, TName, @@ -130,7 +131,7 @@ interface ArrayBufferTypeFieldDefinitionCreator< < TName extends PropertyKey, - TLengthField extends KeysOfType, + TLengthField extends LengthField, TOptions extends VariableLengthArrayBufferLikeFieldOptions, TTypeScriptType = TType['valueType'], >( @@ -139,7 +140,7 @@ interface ArrayBufferTypeFieldDefinitionCreator< typescriptType?: TTypeScriptType, ): AddFieldDescriptor< TFields, - TOmitInit, + TOmitInitKey, TExtra, TPostDeserialized, TName, @@ -158,7 +159,7 @@ export type StructDeserializedType implements StructLike>{ diff --git a/packages/struct/src/types/array-buffer.ts b/packages/struct/src/types/array-buffer.ts index b8af0f2f..1b0a7b55 100644 --- a/packages/struct/src/types/array-buffer.ts +++ b/packages/struct/src/types/array-buffer.ts @@ -102,7 +102,7 @@ const EmptyArrayBuffer = new ArrayBuffer(0); export abstract class ArrayBufferLikeFieldDefinition< TType extends ArrayBufferLikeFieldType = ArrayBufferLikeFieldType, TOptions = void, - TOmitInitKey = never, + TOmitInitKey extends PropertyKey = never, > extends StructFieldDefinition< TOptions, TType['valueType'], diff --git a/packages/struct/src/types/variable-length-array-buffer.ts b/packages/struct/src/types/variable-length-array-buffer.ts index 952bbdea..3b445dbe 100644 --- a/packages/struct/src/types/variable-length-array-buffer.ts +++ b/packages/struct/src/types/variable-length-array-buffer.ts @@ -2,9 +2,11 @@ import { StructFieldValue, StructOptions, StructSerializationContext, StructValu import type { KeysOfType } from '../utils'; import { ArrayBufferLikeFieldDefinition, ArrayBufferLikeFieldType, ArrayBufferLikeFieldValue } from './array-buffer'; +export type LengthField = KeysOfType; + export interface VariableLengthArrayBufferLikeFieldOptions< TFields = object, - TLengthField extends KeysOfType = any, + TLengthField extends LengthField = any, > { lengthField: TLengthField; }