Skip to content

feat: add strong type safety for IconDefinition callbacks and support some object options#13

Open
danilo-arioli wants to merge 9 commits intowaspeer:mainfrom
danilo-arioli:feat/strong-types
Open

feat: add strong type safety for IconDefinition callbacks and support some object options#13
danilo-arioli wants to merge 9 commits intowaspeer:mainfrom
danilo-arioli:feat/strong-types

Conversation

@danilo-arioli
Copy link

@danilo-arioli danilo-arioli commented Dec 19, 2025

This PR adds full type safety to the IconDefinition schema type. Schema callbacks that use the icon field now receive correct types for the value parameter in validation, hidden, and readOnly. It also introduces the collapsible and collapsed object options to IconDefinition and adds tests covering these changes.

Before

defineField({
  name: 'icon',
  title: "Icon",
  type: 'icon',
  // ❌ Error 1: Parameter 'Rule' implicitly has an 'any' type
  // ❌ Error 2: Parameter 'value' implicitly has an 'any' type
  validation: (Rule) => Rule.custom((value) => value?.name === 'lucide:home' ? true : 'Wrong icon'),
  // ❌ value has an 'any' type
  hidden: ({value}) => value?.name === 'lucide:home' ? true : false,
  // ❌ value has an 'any' type
  readOnly: ({value}) => value?.name === 'lucide:home' ? true : false,
  options: {
    // ❌ Error: Object literal may only specify known properties, 
    // and 'collapsible' does not exist in type 'IconOptions'
    collapsible: false,
  },
})

After

defineField({
  name: 'icon',
  title: "Icon",
  type: 'icon',
  // ✅ Rule has a defined type
  // ✅ value type is automatically inferred as {name?: string} | undefined
  validation: (Rule) => Rule.custom((value) => value?.name === 'lucide:home' ? true : 'Wrong icon'),
  // ✅ value type is automatically inferred as {name?: string} | undefined
  hidden: ({value}) => value?.name === 'lucide:home' ? true : false,
  // ✅ value type is automatically inferred as {name?: string} | undefined
  readOnly: ({value}) => value?.name === 'lucide:home' ? true : false,
  options: {
    // ✅ No error - collapsible is now supported
    collapsible: false,
  },
})

@danilo-arioli danilo-arioli marked this pull request as draft December 19, 2025 16:25
@danilo-arioli danilo-arioli changed the title feat: strongly type IconDefinition feat: add strong type safety for IconDefinition callbacks and support some object options Dec 19, 2025
@danilo-arioli danilo-arioli marked this pull request as ready for review December 19, 2025 17:10
@waspeer
Copy link
Owner

waspeer commented Dec 21, 2025

Thank you for this comprehensive pr!! I'll have some time hopefully tomorrow to go over it.

@danilo-arioli
Copy link
Author

Thank you! I also added the initialValue type, which I realized I’d forgotten earlier

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants