Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document search option "pluck" is rejected by TypeScript #436

Open
mikecat opened this issue Apr 13, 2024 · 0 comments
Open

document search option "pluck" is rejected by TypeScript #436

mikecat opened this issue Apr 13, 2024 · 0 comments

Comments

@mikecat
Copy link

mikecat commented Apr 13, 2024

The README.md says:

When using pluck instead of "field" you can explicitly select just one field and get back a flat representation:

index.search(query, { pluck: "title", enrich: true });

However, actually using this option in a TypeScript code (by copy-and-pasting the example) resulted in an error.

Environment:

  • Windows 11 Home 23H2
  • Node.js v20.12.2
  • TypeScript 5.4.5
  • FlexSearch 0.7.43

Source file test-pluck.ts:

import { Document } from "flexsearch";

const index = new Document({
  encode: (str) => str.split(" "),
  document: {
    id: "id",
    index: "title",
  },
});

index.add(0, { title: "test hoge" });

const query = "test";
const res = index.search(query, { pluck: "title", enrich: true });
console.log(res);

Commands:

npm i -D typescript
npm i flexsearch
npx tsc test-pluck.ts

Result (error):

test-pluck.ts:14:19 - error TS2769: No overload matches this call.
  Overload 1 of 4, '(query: string, limit?: number): SimpleDocumentSearchResultSetUnit[]', gave the following error.
    Argument of type '{ pluck: string; enrich: boolean; }' is not assignable to parameter of type 'number'.
  Overload 2 of 4, '(query: string, options: string[] | Partial<DocumentSearchOptions<boolean>>): SimpleDocumentSearchResultSetUnit[]', gave the following error.
    Object literal may only specify known properties, and 'pluck' does not exist in type 'string[] | Partial<DocumentSearchOptions<boolean>>'.
  Overload 3 of 4, '(query: string, limit?: number, options?: Partial<DocumentSearchOptions<false>>): SimpleDocumentSearchResultSetUnit[]', gave the following error.
    Argument of type '{ pluck: string; enrich: boolean; }' is not assignable to parameter of type 'number'.

14 const res = index.search(query, { pluck: "title", enrich: true });
                     ~~~~~~



Found 1 error in test-pluck.ts:14
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

No branches or pull requests

1 participant