Skip to content

feat(types): migrate components to script setup with generic types#324

Merged
bnjm merged 1 commit intomainfrom
generic-options
Dec 18, 2025
Merged

feat(types): migrate components to script setup with generic types#324
bnjm merged 1 commit intomainfrom
generic-options

Conversation

@bnjm
Copy link
Contributor

@bnjm bnjm commented Dec 11, 2025

Vue components support generics since v3.3 and this PR introduces them, alongside a few other low-hanging type improvements, for several of the selection/list components. Changes (will be squashed):

  • migrate selection components to Vue 3 <script setup> - this seems to result in better prop type generation in the bundle.d.ts files
  • update:modelValue now preserves type
// before: no type error even with wrong type
const selected = ref<number>(123)
<ACombobox v-model="selected" :options="stringOptions" /> <!-- runtime failure only -->
// after: type error if mismatched
const selected = ref<number>(123)
<ACombobox v-model="selected" :options="stringOptions" /> <!-- type error: number not assignable to string -->
  • slot props preserve option type
<!-- before: option typed as generic Option, no autocomplete for custom fields -->
<AListbox :options="customOptions">
  <template #default="{ option }">
    {{ option.metadata }} <!-- property 'metadata' does not exist -->
  </template>
</AListbox>

<!-- after: full type inference -->
<AListbox :options="customOptions">
  <template #default="{ option }">
    {{ option.metadata.priority }} <!-- autocomplete works -->
  </template>
</AListbox>
  • filterCallback receives typed option
<!-- before -->
<ACombobox :filter-callback="(opt, q) => opt.customField.includes(q)" />
<!-- property doesn't exist -->

<!-- after -->
<ACombobox :filter-callback="(opt, q) => opt.customField.includes(q)" />
<!-- works with custom option type -->
  • centralised types in src/types/selection.ts
export interface BaseOption<V extends OptionValue = string> {
  value: V
  label: string
  disabled?: boolean
}

// type guards
export function areOptionsGrouped<V, T>(...): ...
export function isOptionGroup<V, T>(...): ... 

@bnjm bnjm requested a review from a team December 11, 2025 13:57
@github-actions
Copy link

🎉 This PR is included in version 2.23.0-test-icon-props.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@bnjm bnjm merged commit 039f79b into main Dec 18, 2025
1 check passed
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.

1 participant