diff --git a/types/match-sorter/index.d.ts b/types/match-sorter/index.d.ts index dd4f5bc5a7..638f2b54fe 100644 --- a/types/match-sorter/index.d.ts +++ b/types/match-sorter/index.d.ts @@ -1,7 +1,8 @@ -// Type definitions for match-sorter 2.3 +// Type definitions for match-sorter 4.0 // Project: https://github.com/kentcdodds/match-sorter#readme // Definitions by: Claas Ahlrichs // Christian Ruigrok +// Timo Riski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 @@ -20,13 +21,16 @@ declare namespace matchSorter { } } -type ExtendedKeyOptions = { key: string | ((item: T) => string) } & ( +type KeyOptions = string | ((item: T) => string | string[]); + +type ExtendedKeyOptions = { key: KeyOptions } & ( | { minRanking: number } | { maxRanking: number } - | { threshold: number }); + | { threshold: number } +); interface Options { - keys?: Array string) | ExtendedKeyOptions>; + keys?: Array | ExtendedKeyOptions>; threshold?: number; keepDiacritics?: boolean; } @@ -38,10 +42,6 @@ interface Options { * @param options - Some options to configure the sorter * @return the new sorted array */ -declare function matchSorter( - items: ReadonlyArray, - value: string, - options?: Options -): T[]; +declare function matchSorter(items: ReadonlyArray, value: string, options?: Options): T[]; export = matchSorter; diff --git a/types/match-sorter/match-sorter-tests.ts b/types/match-sorter/match-sorter-tests.ts index a6529f7998..6d634984ca 100644 --- a/types/match-sorter/match-sorter-tests.ts +++ b/types/match-sorter/match-sorter-tests.ts @@ -70,6 +70,29 @@ import matchSorter = require('match-sorter'); matchSorter(list, 'j', { keys: [item => item.name] }); // [{name: 'Janice'}, {name: 'Jen'}] } +{ + const tea = [ + { tea: 'Earl Grey', alias: 'A' }, + { tea: 'Assam', alias: 'B' }, + { tea: 'Black', alias: 'C' } + ]; + matchSorter(tea, 'e', { keys: [item => [item.tea, item.alias]] }); + // [{tea: 'Earl Grey', alias: 'A'}] +} +{ + const tea = [ + { tea: 'Earl Grey', alias: 'A' }, + { tea: 'Assam', alias: 'B' }, + { tea: 'Black', alias: 'C' } + ]; + matchSorter(tea, 'e', { + keys: [{ + key: item => [item.alias, item.tea], + minRanking: matchSorter.rankings.EQUAL + }] + }); + // [{tea: 'Earl Grey', alias: 'A'}] +} // ### Min and Max Ranking {