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

Typescript types incompatible on examplecode #847

Closed
gmuc opened this issue Mar 7, 2024 · 1 comment
Closed

Typescript types incompatible on examplecode #847

gmuc opened this issue Mar 7, 2024 · 1 comment
Labels

Comments

@gmuc
Copy link

gmuc commented Mar 7, 2024

Usage questions

I had installed your demo code like you describe it and run the file react-bootstrap-typeahead/example/index.html.
It work like on your live demo!

But if I look in the code of examples/CustomFilteringExample.tsx with my VS Code there is a typescript error.

The text:

Type '((option: Option, props: any) => boolean) | string[]' is not assignable to type 'string[] | FilterByCallback | undefined'.
Type '(option: Option, props: any) => boolean' is not assignable to type 'string[] | FilterByCallback | undefined'.
Type '(option: Option, props: any) => boolean' is not assignable to type 'FilterByCallback'.
Types of parameters 'option' and 'option' are incompatible.
Type 'import("/Users/gerdmucha/projekte/wetter/cirrus23/test_typeahead/node_modules/react-bootstrap-typeahead/types/types").Option' is not assignable to type 'import("/Users/gerdmucha/projekte/wetter/cirrus23/test_typeahead/react-bootstrap-typeahead/example/src/data").Option'.
Type 'string' is not assignable to type 'Option'.ts(2322)
types.d.ts(36, 5): The expected type comes from property 'filterBy' which is declared here on type 'IntrinsicAttributes & TypeaheadComponentProps & RefAttributes'

How can I fix this?

Version v6.3.2

Steps to reproduce

Looking code of examples/CustomFilteringExample.tsx with my VS Code

@gmuc gmuc added the bug label Mar 7, 2024
@ericgio
Copy link
Owner

ericgio commented Feb 10, 2025

This is the same issue as described in #704. Basically, the Option type being used in the component doesn't accept a generic type that conforms to case-by-case data. See the discussion in the other issue, but basically it's difficult to solve "correctly" in the library itself, since that type is propagated throughout. The simplest workaround unfortunately is to do type casting or tell TS to ignore the error.

@ericgio ericgio closed this as completed Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants