From fed95fec69a45c72bef73093c7e4c2a4ccb372bd Mon Sep 17 00:00:00 2001 From: Pacifique Linjanja Date: Mon, 18 Nov 2024 10:12:43 +0200 Subject: [PATCH] fix: ensure proper type association for nestedProperties in data type configuration - Resolved incorrect handling of `nestedProperties` for non-object data types. - Introduced `ObjectDataType` and `PrimitiveDataType` for improved type distinction. - Updated `NestedPropertyCreate` and `NestedPropertyConfigCreate` to align with conditional `dataType` logic. - Improved type safety and consistency in data type configurations. --- src/collections/configure/types/base.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/collections/configure/types/base.ts b/src/collections/configure/types/base.ts index a2934ca1..d279ab96 100644 --- a/src/collections/configure/types/base.ts +++ b/src/collections/configure/types/base.ts @@ -36,17 +36,32 @@ export type MultiTenancyConfigUpdate = { autoTenantCreation?: boolean; }; +export type ObjectDataType = 'object' | 'object[]'; + +export type PrimitiveDataType = Exclude; + +export type NestedDataTypeConfig = + | { + dataType: ObjectDataType; + /** only for object types */ + nestedProperties?: NestedPropertyConfigCreate[]; + } + | { + dataType: PrimitiveDataType; + /** If not an object, or an array of objecs, this field should never be assigned. */ + nestedProperties?: never; + }; + export type NestedPropertyCreate = T extends undefined ? { name: string; dataType: DataType; description?: string; - nestedProperties?: NestedPropertyConfigCreate[]; indexInverted?: boolean; indexFilterable?: boolean; indexSearchable?: boolean; tokenization?: WeaviateNestedProperty['tokenization']; - } + } & NestedDataTypeConfig : { [K in NonRefKeys]: RequiresNested> extends true ? { @@ -92,9 +107,7 @@ export type NestedPropertyConfigCreateBase = { export type PropertyConfigCreate = T extends undefined ? { name: string; - dataType: DataType; description?: string; - nestedProperties?: NestedPropertyConfigCreate[]; indexInverted?: boolean; indexFilterable?: boolean; indexRangeFilters?: boolean; @@ -102,7 +115,7 @@ export type PropertyConfigCreate = T extends undefined tokenization?: WeaviateProperty['tokenization']; skipVectorization?: boolean; vectorizePropertyName?: boolean; - } + } & NestedDataTypeConfig : { [K in NonRefKeys]: RequiresNested> extends true ? {