Fuse
Fuse copied to clipboard
feat: refine type includeMatches and includeScore
For better type infer
const data = [{ id: '1' }]
{
const fuse = new Fuse(data, {
keys: ['id'],
includeScore: true
})
const r = fuse.search('1')
// ok
r.sort((a, b) => a.score - b.score)
}
{
const fuse = new Fuse(data, {
keys: ['id']
})
const r = fuse.search('1')
// error: Property 'score' does not exist on type '{ item: { id: string; }; refIndex: number; }'
r.sort((a, b) => a.score - b.score)
}
{
const fuse = new Fuse(data, {
keys: ['id'],
includeMatches: true
})
const r = fuse.search('1')
// ok
r.sort((a, b) => a.matches.length - b.matches.length)
}
{
const fuse = new Fuse(data, {
keys: ['id'],
includeMatches: false
})
const r = fuse.search('1')
// error: Property 'matches' does not exist on type '{ item: { id: string; }; refIndex: number; }'.
r.sort((a, b) => a.matches.length - b.matches.length)
}