Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:displayValue="(person) => person.name"; Object is of type 'unknown'.ts(2571) #1332

Closed
StefanGhiban opened this issue Apr 14, 2022 · 8 comments

Comments

@StefanGhiban
Copy link

What package within Headless UI are you using?

@headlessui/vue

What version of that package are you using?

1.5.0

What browser are you using?

Chrome

Describe your issue

The comboxbox input attribute displayValue has a signature of "displayValue?: ((item: unknown) => string) | undefined", which throws an error in vue with ts. We can't access a property of an object that has type unknown.

@flutcon
Copy link

flutcon commented Apr 19, 2022

@StefanGhiban , I ran into the same issue - how did you get it solved?

@StefanGhiban
Copy link
Author

@flutcon due to the function taking an unknown argument as input, I have used a type assertion as following:

:displayValue="(option) => (option as Test).label"

Test being an interface with key, label and values as attributes.

@faithfulojebiyi
Copy link

@StefanGhiban this does not work in vue

@srisar
Copy link

srisar commented Sep 1, 2022

The solution proposed is not working on Vue too

@StefanGhiban
Copy link
Author

@faithfulojebiyi @srisar It worked fine for me. Do you have a solution or a workaround for this issue?

@hymair
Copy link

hymair commented Nov 10, 2022

If you are using this directly in the template it would work out of the box in Vue 3 because it parses templates for typescript.

For Vue 2 you should reference a function in the template :display-value="displayValue" and define that in your script tag.

function displayValue(value: unknown) {
    return (value as YourType)?.someProp ?? ''
}

@ElvisGmz
Copy link

ElvisGmz commented Jul 5, 2023

:display-value="(person: any) => person.value"

For me works 🤔

@brokuka
Copy link

brokuka commented Jul 5, 2023

actual bug btw

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

No branches or pull requests

7 participants