Skip to content

Commit

Permalink
fix(typescript): type definition for FuseOptionKeyObject
Browse files Browse the repository at this point in the history
fixes #655 #656
  • Loading branch information
krisk committed May 6, 2022
1 parent da6e399 commit 0a790b5
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,8 @@ declare namespace Fuse {
// 'n': 0.5773502691896258
// }
type RecordEntryObject = {
/** The text value */
v: string
/** The field-length norm */
n: number
v: string // The text value
n: number // The field-length norm
}

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

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

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

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

// {
// name: 'title',
// weight: 0.7,
// getFn: (book) => book.title
// weight: 0.7
// }
export type FuseOptionKeyObject<T> = {
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. */
name: string | string[]
weight?: number
/** The function to use to retrieve an object's value */
getFn?: FuseOptionKeyObjectGetFunction<T>
getFn?: (obj: T) => ReadonlyArray<string> | string
}

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

1 comment on commit 0a790b5

@BenJenkinson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krisk Thanks for merging this. Was there a problem with the intellisense code comments I added?

Please sign in to comment.