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] FuseOptionKeyObject type doesn't match the implementation #655

Closed
BenJenkinson opened this issue May 5, 2022 · 1 comment · Fixed by #656 or #659
Closed

[Typescript] FuseOptionKeyObject type doesn't match the implementation #655

BenJenkinson opened this issue May 5, 2022 · 1 comment · Fixed by #656 or #659
Labels

Comments

@BenJenkinson
Copy link
Contributor

The FuseOptionKeyObject type definition doesn't match the implementation.

Fuse/src/index.d.ts

Lines 234 to 239 in 6afcfaf

export type FuseOptionKeyObject = {
name: string | string[]
weight: number
}
export type FuseOptionKey = FuseOptionKeyObject | string | string[]

  • The weight property may be optional. (Since if not specified, Fuse will default it to 1)

if (hasOwn.call(key, 'weight')) {
weight = key.weight
if (weight <= 0) {
throw new Error(ErrorMsg.INVALID_KEY_WEIGHT_VALUE(name))
}
}

  • The getFn property is missing.

Fuse/docs/examples.md

Lines 170 to 180 in 6afcfaf

const options = {
includeScore: true,
keys: [
{ name: 'title', getFn: (book) => book.title },
{ name: 'authorName', getFn: (book) => book.author.name }
]
})
const fuse = new Fuse(list, options)
const result = fuse.search({ authorName: 'Steve' })

Version

6.6.0

Is this a regression?

No

🔬Minimal Reproduction (in Typescript)

  • The weight property cannot be omitted without an error.
  • The getFn example from the docs cannot be written without an error.
BenJenkinson added a commit to BenJenkinson/Fuse that referenced this issue May 5, 2022
### Changes
- **Make `FuseOptionKeyObject.weight` property optional (and add description taken from docs)**
- **Add `FuseOptionKeyObject.getFn` property (and add description taken from docs)**
- Add `FuseOptionKeyObjectGetFunction` type to match existing `FuseGetFunction` type
- Make `FuseOptionKeyObject` a generic, to allow typing the `getFn` method argument
- Make `FuseOptionKey` a generic, to allow making `FuseOptionKeyObject` a generic
- Convert some existing inline comments `// foo` to jsdoc comments `/** foo */` so they will be included in intellisense

### Related issues
- Fixes krisk#655

### See also
- PR krisk#648
BenJenkinson added a commit to BenJenkinson/Fuse that referenced this issue May 5, 2022
…k#655

- Make `FuseOptionKeyObject.weight` property optional (and add description taken from docs)
- Add `FuseOptionKeyObject.getFn` property (and add description taken from docs)
- Add `FuseOptionKeyObjectGetFunction` type to match existing `FuseGetFunction` type
- Make `FuseOptionKeyObject` a generic, to allow typing the `getFn` method argument
- Make `FuseOptionKey` a generic, to allow making `FuseOptionKeyObject` a generic
- Convert some existing inline comments `// foo` to jsdoc comments `/** foo */` so they will be included in intellisense
BenJenkinson added a commit to BenJenkinson/Fuse that referenced this issue May 5, 2022
…k#655

- Make `FuseOptionKeyObject.weight` property optional (and add description taken from docs)
- Add `FuseOptionKeyObject.getFn` property (and add description taken from docs)
- Add `FuseOptionKeyObjectGetFunction` type to match existing `FuseGetFunction` type
- Make `FuseOptionKeyObject` a generic, to allow typing the `getFn` method argument
- Make `FuseOptionKey` a generic, to allow making `FuseOptionKeyObject` a generic
- Convert some existing inline comments `// foo` to jsdoc comments `/** foo */` so they will be included in intellisense
@krisk
Copy link
Owner

krisk commented May 6, 2022

Does look like a regression specifically for the getFn part. Will address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants