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

fix(typescript): type definition for FuseOptionKeyObject, fixes #655 #656

Merged
merged 2 commits into from
May 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ declare namespace Fuse {
// 'n': 0.5773502691896258
// }
type RecordEntryObject = {
v: string // The text value
n: number // The field-length norm
/** The text value */
v: string
/** The field-length norm */
n: number
}

// 'author.tags.name': [{
Expand All @@ -205,7 +207,8 @@ declare namespace Fuse {
// }
// }
type FuseIndexObjectRecord = {
i: number // The index of the record in the source list
/** The index of the record in the source list */
i: number
$: RecordEntry
}

Expand All @@ -218,23 +221,33 @@ declare namespace Fuse {
// ]
// }
type FuseIndexStringRecord = {
i: number // The index of the record in the source list
v: string // The text value
n: number // The field-length norm
/** The index of the record in the source list */
i: number
/** The text value */
v: string
/** The field-length norm */
n: number
}

type FuseIndexRecords =
| ReadonlyArray<FuseIndexObjectRecord>
| ReadonlyArray<FuseIndexStringRecord>

type FuseOptionKeyObjectGetFunction<T> = (
obj: T,
) => ReadonlyArray<string> | string

// {
// name: 'title',
// weight: 0.7
// weight: 0.7,
// getFn: (book) => book.title
// }
export type FuseOptionKeyObject<T> = {
name: string | string[]
name: string | string[]
/** Adjust the weight of each key to give them higher (or lower) values in search results. The `weight` value must be greater than zero. If undefined, it will default to `1`. Internally, Fuse will normalize weights to be within `0` and `1` exclusive. */
weight?: number
getFn?: (obj: T) => ReadonlyArray<string> | string
/** The function to use to retrieve an object's value */
getFn?: FuseOptionKeyObjectGetFunction<T>
}

export type FuseOptionKey<T> = FuseOptionKeyObject<T> | string | string[]
Expand Down