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

Typescript compile issue with addField #113

Open
figelwump opened this issue Jan 30, 2020 · 2 comments
Open

Typescript compile issue with addField #113

figelwump opened this issue Jan 30, 2020 · 2 comments

Comments

@figelwump
Copy link

I'm using elasticlunr in a typescript project. I get the following typescript compiler error when using addField:

[0] Argument of type '"url"' is not assignable to parameter of type 'never'.  TS2345

The code:

            let elasticLunrIndex = elasticlunr(function () {
                this.addField('url');
            });

I made sure all strict checking is turned off in tsconfig.json. I can workaround it for now by casting the string to never (whatever that means) like so:

            let elasticLunrIndex = elasticlunr(function () {
                this.addField('url' as never);
            });
@sebastiansandqvist
Copy link

Looking at the typings for elasticlunr it looks like there's a constructor argument that determines what strings are valid to pass to this.addField.

So to fix your problem:

interface Foo {
  url: string;
}

let elasticLunrIndex = elasticlunr<Foo>(function () {
  this.addField('url');
});

@larrystone
Copy link

Also check out a more relaxed approach here

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

3 participants