You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(typescript): type definition for `FuseOptionKeyObject, fixes#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
Copy file name to clipboardExpand all lines: src/index.d.ts
+27-13Lines changed: 27 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ declare class Fuse<T> {
86
86
* @returns An indexed list
87
87
*/
88
88
staticcreateIndex<U>(
89
-
keys: Array<Fuse.FuseOptionKey>,
89
+
keys: Array<Fuse.FuseOptionKey<U>>,
90
90
list: ReadonlyArray<U>,
91
91
options?: Fuse.FuseIndexOptions<U>
92
92
): Fuse.FuseIndex<U>
@@ -178,8 +178,10 @@ declare namespace Fuse {
178
178
// 'n': 0.5773502691896258
179
179
// }
180
180
typeRecordEntryObject={
181
-
v: string// The text value
182
-
n: number// The field-length norm
181
+
/** The text value */
182
+
v: string
183
+
/** The field-length norm */
184
+
n: number
183
185
}
184
186
185
187
// 'author.tags.name': [{
@@ -205,7 +207,8 @@ declare namespace Fuse {
205
207
// }
206
208
// }
207
209
typeFuseIndexObjectRecord={
208
-
i: number// The index of the record in the source list
210
+
/** The index of the record in the source list */
211
+
i: number
209
212
$: RecordEntry
210
213
}
211
214
@@ -218,25 +221,36 @@ declare namespace Fuse {
218
221
// ]
219
222
// }
220
223
typeFuseIndexStringRecord={
221
-
i: number// The index of the record in the source list
222
-
v: string// The text value
223
-
n: number// The field-length norm
224
+
/** The index of the record in the source list */
225
+
i: number
226
+
/** The text value */
227
+
v: string
228
+
/** The field-length norm */
229
+
n: number
224
230
}
225
231
226
232
typeFuseIndexRecords=
227
233
|ReadonlyArray<FuseIndexObjectRecord>
228
234
|ReadonlyArray<FuseIndexStringRecord>
235
+
236
+
typeFuseOptionKeyObjectGetFunction<T>=(
237
+
obj: T,
238
+
)=>ReadonlyArray<string>|string
229
239
230
240
// {
231
241
// name: 'title',
232
-
// weight: 0.7
242
+
// weight: 0.7,
243
+
// getFn: (book) => book.title
233
244
// }
234
-
exporttypeFuseOptionKeyObject={
235
-
name: string|string[]
236
-
weight: number
245
+
exporttypeFuseOptionKeyObject<T>={
246
+
name: string|string[]
247
+
/** 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. */
248
+
weight?: number
249
+
/** The function to use to retrieve an object's value */
/** Indicates whether comparisons should be case sensitive. */
@@ -258,7 +272,7 @@ declare namespace Fuse {
258
272
/** Whether the score should be included in the result set. A score of `0`indicates a perfect match, while a score of `1` indicates a complete mismatch. */
259
273
includeScore?: boolean
260
274
/** List of keys that will be searched. This supports nested paths, weighted search, searching in arrays of `strings` and `objects`. */
261
-
keys?: Array<FuseOptionKey>
275
+
keys?: Array<FuseOptionKey<T>>
262
276
/** Determines approximately where in the text is the pattern expected to be found. */
263
277
location?: number
264
278
/** Only the matches whose length exceeds this value will be returned. (For instance, if you want to ignore single character matches in the result, set it to `2`). */
0 commit comments