Skip to content
New issue

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

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

Already on GitHub? # to your account

TypeScript doesn't allow omitting id from the document descriptor while the README says it is allowed #435

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

Comments

@mikecat
Copy link

mikecat commented Apr 13, 2024

The README.md says:

The default key gets the value id by default when not passed, so you can shorten the example from above to:

const index = new Document({
    document: {
        index: ["content"]
    }
});

However, copy-and-pasting this code to a TypeScript code 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-id.ts:

import { Document } from "flexsearch";

const index = new Document({
    document: {
        index: ["content"]
    }
});

Commands:

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

Result (error):

test-id.ts:4:5 - error TS2322: Type '{ index: string[]; }' is not assignable to type 'DocumentOptions<unknown, false> | Descriptor<unknown, false>'.
  Property 'id' is missing in type '{ index: string[]; }' but required in type 'DocumentOptions<unknown, false>'.

4     document: {
      ~~~~~~~~

  node_modules/flexsearch/index.d.ts:285:9
    285         id: string;
                ~~
    'id' is declared here.
  node_modules/flexsearch/index.d.ts:304:9
    304         document?: DocumentOptions<T, Store> | Descriptor<T, Store>;
                ~~~~~~~~
    The expected type comes from property 'document' which is declared here on type 'IndexOptionsForDocumentSearch<unknown, false>'


Found 1 error in test-id.ts:4
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant