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

The type for Fuse.search defaults to unknown #527

Closed
qnighy opened this issue Jan 4, 2021 · 3 comments
Closed

The type for Fuse.search defaults to unknown #527

qnighy opened this issue Jan 4, 2021 · 3 comments
Labels

Comments

@qnighy
Copy link

qnighy commented Jan 4, 2021

Describe the bug

2e60bee changed the signature of Fuse.prototype.search.

  search<T>(
    pattern: string | Fuse.Expression,
    options?: Fuse.FuseSearchOptions
  ): Fuse.FuseResult<T>[]

Here T isn't constrained by any of the arguments. Therefore it defaults to unknown, making it meaningless.

I guess search<T>(...) was meant to be search(...), using T from the outer Fuse<T>?

Version

Fuse 6.4.5

Is this a regression?

Yes. Previously the type parameter was named R and was defaulted to T from the outer class Fuse<T>.

🔬Minimal Reproduction

declare const fuse: Fuse<{ id: number }>;
const matchedIds = fuse.search("").map(res => res.item.id);

Additional context

@qnighy qnighy added the bug label Jan 4, 2021
@nwaughachukwuma
Copy link

@qnighy @krisk, to resolve the issue where the type is lost and defaults to unknown, I had to the following - using the minimal reproduction above:

type K = { id: number }
declare const fuse: Fuse<K>;
const matchedIds = fuse.search<K>("").map(res => res.item.id); // <-- notice the type parameter in `search<K>`

This was not the case before and the fix pointed by @qnighy should solve this.

I guess search(...) was meant to be search(...), using T from the outer Fuse?

@krisk
Copy link
Owner

krisk commented Jan 5, 2021

Good catch. Will fix.

@krisk krisk closed this as completed in 94766b2 Jan 5, 2021
@qnighy
Copy link
Author

qnighy commented Jan 6, 2021

Thanks!

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

3 participants