Open ameytessact opened 1 month ago
@ameytessact Hi, you could fix the type error by following code
export const Listbox = extendVariants(NextListBox, {
defaultVariants: {
variant: "default",
},
variants: {
variant: {
default: {
base: "p-2 bg-ds-menu-bg border-ds-menu-border border rounded-xl",
list: "space-y-1",
},
},
},
}) as typeof NextListBox;
export const ListboxItem = extendVariants(NextListboxItem, {
defaultVariants: {
variant: "default",
},
variants: {
variant: {
default: {
base: "bg-transparent data-[hover=true]:bg-ds-menu-bg-hover",
description: "text-ds-menu-text-secondary",
},
},
},
}) as typeof NextListboxItem;
Cause the ListBox
compoent you extending is needed to infer the Items type by T
generics
NextUI Version
2.3.0
Describe the bug
A listbox component that is extended does not infer the types correctly.
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
I have a simple Listbox that uses dynamic items as follows:
I am getting an typescript error for the type of
item
.Here is how I've extended my Listbox component:
Expected behavior
This error gets fixed automatically if I use the next ui component directly as such:
item
also get the correct type inferred instad ofunknown
I expect the extended component to infer the type correctly as well.
Screenshots or Videos
No response
Operating System Version
Ubuntu 24.04
Browser
Chrome