Skip to content

Conversation

@Rot4tion
Copy link
Contributor

Summary

Improves TypeScript type safety for siblingData across field configuration types by introducing a StripRelationships utility type that removes populated relationship objects, keeping the ID type (number or string) base on database config.

const siblingData = {
  creator: 1,                    // Relationship field
  _status: 'draft',
  title:"abc",
  updatedAt: '2025-12-11T07:52:22.115Z',
  createdAt: '2025-12-11T07:13:24.433Z',
  attributes: [3, 2],            // Relationship hasMany
  description: {                 // RichText field
    root: {
      type: 'root',
      children: [...],
    }
  },
}

} // RichText field


// Before (Incorrect Types)
type SiblingData = {
  [key: string]: any
} | undefined

// Or with Partial<TData>:
type SiblingData = {
  creator: number | User | undefined      // ❌ Includes populated object
  attributes?: (number | Attribute)[]     // ❌ Includes populated objects
  ...
}


// After (Correct Types)

type SiblingData = {
  id: number | undefined
  creator: number | undefined              // ✅ ID only
  title: string | undefined
  description: {
    [k: string]: unknown
    root: {
      type: string
      children: { type: any; version: number }[]
      direction: 'rtl' | 'ltr' | null
      format: '' | 'center' | 'left' | 'right' | 'start' | 'end' | 'justify'
      indent: number
      version: number
    }
  } | undefined
  attributes?: number[] | null             // ✅ IDs only
  updatedAt: string | undefined
  createdAt: string | undefined
   _status?: "draft" | "published" | null
}

} from '../validations.js'

export type FieldHookArgs<TData extends TypeWithID = any, TValue = any, TSiblingData = any> = {
export type FieldHookArgs<TData extends TypeWithID = any, TValue = any, TSiblingData = TData> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TData !== TSiblingData if you're in a group field. I'd rather have it typed weakly (any) than potentially incorrectly

Copy link
Contributor Author

@Rot4tion Rot4tion Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see the issue, pls check my new commit

image image

Rollback TSiblingData generic parameter default from `TData` to `any` across FieldHookArgs, FieldHook, FieldAccessArgs, FieldAccess, Condition, and FilterOptionsProps types. This allows siblingData to have a different type than the top-level document data, improving type flexibility for nested field structures.

Add TSiblingData type to FilterOptionsProps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants