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 wrong type #774

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
28 changes: 18 additions & 10 deletions dist/fuse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,21 @@ type FuseSortFunctionItem = {
* }
* ```
*/
type FuseSortFunctionMatch = {
type FuseSortFunctionMatch<T> = {
score: number
key: string
key: FuseSortFunctionMatchKey<T>
value: string
indices: ReadonlyArray<number>[]
}

interface FuseSortFunctionMatchKey<T> {
id: string
getFn?: FuseGetFunction<T>
path: string[]
src: string
weight: number
}

/**
* @example
* ```ts
Expand All @@ -172,20 +180,20 @@ type FuseSortFunctionMatch = {
* }
* ```
*/
type FuseSortFunctionMatchList = FuseSortFunctionMatch & {
type FuseSortFunctionMatchList<T> = FuseSortFunctionMatch<T> & {
idx: number
}

type FuseSortFunctionArg = {
type FuseSortFunctionArg<T> = {
idx: number
item: FuseSortFunctionItem
score: number
matches?: (FuseSortFunctionMatch | FuseSortFunctionMatchList)[]
matches?: (FuseSortFunctionMatch<T> | FuseSortFunctionMatchList<T>)[]
}

type FuseSortFunction = (
a: FuseSortFunctionArg,
b: FuseSortFunctionArg
type FuseSortFunction<T> = (
a: FuseSortFunctionArg<T>,
b: FuseSortFunctionArg<T>
) => number

/**
Expand Down Expand Up @@ -317,7 +325,7 @@ interface IFuseOptions<T> {
/** Whether to sort the result list, by score. */
shouldSort?: boolean
/** The function to use to sort all the results. The default will sort by ascending relevance score, ascending index. */
sortFn?: FuseSortFunction
sortFn?: FuseSortFunction<T>
/** At what point does the match algorithm give up. A threshold of `0.0` requires a perfect match (of both letters and location), a threshold of `1.0` would match anything. */
threshold?: number
/** When `true`, it enables the use of unix-like search commands. See [example](/examples.html#extended-search). */
Expand Down Expand Up @@ -365,4 +373,4 @@ type Expression =
| { $and?: Expression[] }
| { $or?: Expression[] }

export { Expression, FuseGetFunction, FuseIndex, FuseIndexObjectRecord, FuseIndexOptions, FuseIndexRecords, FuseIndexStringRecord, FuseOptionKey, FuseOptionKeyObject, FuseResult, FuseResultMatch, FuseSearchOptions, FuseSortFunction, FuseSortFunctionArg, FuseSortFunctionItem, FuseSortFunctionMatch, FuseSortFunctionMatchList, IFuseOptions, RangeTuple, RecordEntry, RecordEntryArrayItem, RecordEntryObject, Fuse as default };
export { Expression, FuseGetFunction, FuseIndex, FuseIndexObjectRecord, FuseIndexOptions, FuseIndexRecords, FuseIndexStringRecord, FuseOptionKey, FuseOptionKeyObject, FuseResult, FuseResultMatch, FuseSearchOptions, FuseSortFunction, FuseSortFunctionArg, FuseSortFunctionItem, FuseSortFunctionMatch, FuseSortFunctionMatchKey, FuseSortFunctionMatchList, IFuseOptions, RangeTuple, RecordEntry, RecordEntryArrayItem, RecordEntryObject, Fuse as default };
26 changes: 17 additions & 9 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,21 @@ export type FuseSortFunctionItem = {
* }
* ```
*/
export type FuseSortFunctionMatch = {
export type FuseSortFunctionMatch<T> = {
score: number
key: string
key: FuseSortFunctionMatchKey<T>
value: string
indices: ReadonlyArray<number>[]
}

export interface FuseSortFunctionMatchKey<T> {
id: string
getFn?: FuseGetFunction<T>
path: string[]
src: string
weight: number
}

/**
* @example
* ```ts
Expand All @@ -172,20 +180,20 @@ export type FuseSortFunctionMatch = {
* }
* ```
*/
export type FuseSortFunctionMatchList = FuseSortFunctionMatch & {
export type FuseSortFunctionMatchList<T> = FuseSortFunctionMatch<T> & {
idx: number
}

export type FuseSortFunctionArg = {
export type FuseSortFunctionArg<T> = {
idx: number
item: FuseSortFunctionItem
score: number
matches?: (FuseSortFunctionMatch | FuseSortFunctionMatchList)[]
matches?: (FuseSortFunctionMatch<T> | FuseSortFunctionMatchList<T>)[]
}

export type FuseSortFunction = (
a: FuseSortFunctionArg,
b: FuseSortFunctionArg
export type FuseSortFunction<T> = (
a: FuseSortFunctionArg<T>,
b: FuseSortFunctionArg<T>
) => number

/**
Expand Down Expand Up @@ -317,7 +325,7 @@ export interface IFuseOptions<T> {
/** Whether to sort the result list, by score. */
shouldSort?: boolean
/** The function to use to sort all the results. The default will sort by ascending relevance score, ascending index. */
sortFn?: FuseSortFunction
sortFn?: FuseSortFunction<T>
/** At what point does the match algorithm give up. A threshold of `0.0` requires a perfect match (of both letters and location), a threshold of `1.0` would match anything. */
threshold?: number
/** When `true`, it enables the use of unix-like search commands. See [example](/examples.html#extended-search). */
Expand Down