Skip to content

fix(types): allow partial weights object - #295

Open
aleclarson wants to merge 1 commit into
lucaong:masterfrom
aleclarson:fix/weights-option-type
Open

fix(types): allow partial weights object#295
aleclarson wants to merge 1 commit into
lucaong:masterfrom
aleclarson:fix/weights-option-type

Conversation

@aleclarson

Copy link
Copy Markdown

This fixes the type of SearchOptions.weights to allow partial definition.

I also added @default comments for each weight type, to give users a baseline value to tweak in experiments.

Finally, I changed how the default weights are merged into the user-provided weights, ensuring that an explicit undefined value in the user-provided weights doesn‘t prevent the default weight from being used.

@lucaong

lucaong commented Jun 13, 2025

Copy link
Copy Markdown
Owner

Hi @aleclarson , thanks for your contribution! This is a good change, but at the moment the tests are failing due to this typing error:

src/MiniSearch.ts:681:7 - error TS2322: Type '{ fields?: string[]; filter?: (result: SearchResult) => boolean; boost: {}; boostTerm?: (term: string, i: number, terms: string[]) => number; weights: { fuzzy?: number; prefix?: number; }; ... 7 more ...; bm25: BM25Params; }' is not assignable to type 'SearchOptions & { boost: { [fieldName: string]: number; }; weights: { fuzzy: number; prefix: number; }; prefix: boolean | ((term: string, index: number, terms: string[]) => boolean); fuzzy: number | ... 1 more ... | ((term: string, index: number, terms: string[]) => number | boolean); maxFuzzy: number; combineWith: ...'.
      Type '{ fields?: string[]; filter?: (result: SearchResult) => boolean; boost: {}; boostTerm?: (term: string, i: number, terms: string[]) => number; weights: { fuzzy?: number; prefix?: number; }; ... 7 more ...; bm25: BM25Params; }' is not assignable to type '{ boost: { [fieldName: string]: number; }; weights: { fuzzy: number; prefix: number; }; prefix: boolean | ((term: string, index: number, terms: string[]) => boolean); fuzzy: number | boolean | ((term: string, index: number, terms: string[]) => number | boolean); maxFuzzy: number; combineWith: CombinationOperator; bm...'.
        The types of 'weights.fuzzy' are incompatible between these types.
          Type 'number | undefined' is not assignable to type 'number'.
            Type 'undefined' is not assignable to type 'number'.

    681       searchOptions: { ...defaultSearchOptions, ...(options.searchOptions || {}) },
              ~~~~~~~~~~~~~

If you can fix it, I am happy to merge your pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants