flexsearch: Incorrect type definitions
The supplied type definitions are not correct importing the Index as such:
import { Index } from 'flexsearch';
const index = new Index();
results in the error:
'Index' only refers to a type, but is being used as a value here
There exits working type definitions in https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/flexsearch but to use them one has to either downgrade to a version containing no type definitions (e.g. 0.7.11) or delete the supplied one.
It would be awesome if you can sort this out.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 30
- Comments: 20 (2 by maintainers)
Commits related to this issue
- fix(deps): downgrade flexsearch to 0.7.21 We have to downgrade until https://github.com/nextapps-de/flexsearch/issues/342 is fixed. reverts: 0ab88d62e2e21c86e823388548d3250aa58c8ba4 — committed to scope42/scope42 by erikhofer 2 years ago
- fix(geo): do not upgrade flexsearch since it seem not compatible with TS https://github.com/nextapps-de/flexsearch/issues/342 — committed to infra-geo-ouverte/igo2-lib by alecarn 7 months ago
- 1522 update angular v17 (#1543) * fix(geo): do not upgrade flexsearch since it seem not compatible with TS https://github.com/nextapps-de/flexsearch/issues/342 — committed to infra-geo-ouverte/igo2-lib by alecarn 6 months ago
- fic(core): translatemodule forRoot is now called once (#1551) * feat: update Angular v17 * fix(geo): do not upgrade flexsearch since it seem not compatible with TS https://github.com/nextapps-de/... — committed to infra-geo-ouverte/igo2-lib by alecarn 6 months ago
- feat(demo): Convert all components, directives and pipes to standalone * feat: update Angular v17 * fix(geo): do not upgrade flexsearch since it seem not compatible with TS https://github.com/nex... — committed to infra-geo-ouverte/igo2-lib by alecarn 5 months ago
- Release/17.0.0 (#1640) * fix(geo): do not upgrade flexsearch since it seem not compatible with TS https://github.com/nextapps-de/flexsearch/issues/342 * fix(core): translatemodule forRoot is now ... — committed to infra-geo-ouverte/igo2-lib by alecarn 4 months ago
- 1522 update angular v17 (#1543) * fix(geo): do not upgrade flexsearch since it seem not compatible with TS https://github.com/nextapps-de/flexsearch/issues/342 — committed to infra-geo-ouverte/igo2-lib by alecarn 6 months ago
- feat(demo): Convert all components, directives and pipes to standalone * feat: update Angular v17 * fix(geo): do not upgrade flexsearch since it seem not compatible with TS https://github.com/nextap... — committed to infra-geo-ouverte/igo2-lib by alecarn 5 months ago
As the author of
@types/flexsearch, my heart breaks every time when someone replies to this issue and I received the notification. Feel my despair sir. (ㆆᴗㆆ)Just came here wondering if the library was dropped because of how broken the type definitions are. I believe it would be much better to ship without types (just delete index.d.ts) for the sake of not sending wrong signals about the status of the project.
For all of those struggling with this using
pnpmhere is how to install the@types/flexsearchand overwrite the package types.pnpm add @types/flexsearchpnpm patch flexsearchindex.d.tspnpm patch-commit [folder given in step 2]I’d like to if the developers of this library agree to merge the pull request… https://github.com/nextapps-de/flexsearch/pull/266
After updating from
0.7.21to0.7.31it’s completely unclear how to import Document and Index. Is there a guide or changelog to go through?For now that feels like a breaking change
Bump.
Although, if I were in the shoes of @ts-thomas I would drop index.d.t.s and let the community manage the TS typings. As he has said in this thread (quoted below) he isn’t sure about what should be done as the community has varying opinions on how the library should go forward in this regard, so I’d say his best bet is to drop index.d.ts
had to fork it - https://www.npmjs.com/package/flexsearch-ts and swap types with @types/flexsearch happy to PR if others find this useful…
Same problem here when I try to create a Document index with version
0.7.31. When importing likeimport {Document} from 'flexsearch'the provided typings point to:But it should point to something like this
Same issue after upgrading to
0.7.31. The DefinitelyTyped version (which is arguably the correct typing) is being shadowed by the built-in typing atnode_modules/flexsearch/index.d.ts. I have to downgrade to0.7.21.In the meanwhile, @ts-thomas (author of Flexsearch) and @Losses (Author of de-facto the best typing in DefinitelyTyped project), would you consider bringing the DefinitelyTyped version into this repo? The typing files won’t hurt performance and it’s in theory a O(1) complexity change with huge improvement for developers who expect out-of-box typing. The competing library Lyra search, for example, already ships with full typescript support.
I’m experiencing this issue after updating from v0.7.21 to v0.7.31 (I was using this lib with
@types/...definitions before). As of right now it seems completely unusable with typescript (I mean, it works once compiled but it throws type errors everywhere on dev time).I had to rollback to
0.7.21for the time being.100% agree with @fgarcia here. If the official type definitions are not going to be actively maintained but the library is then at least remove them so
@types/flexsearchcan be managed by the community.@ts-thomas would be great if you could remove the index.d.ts from the package/release
basically merging this PR: https://github.com/nextapps-de/flexsearch/pull/366
Up.
Up
I’m using patch-package so that I can continue to use
@types/flexsearchby deleting the providedindex.d.tsfile.