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

TypeDefinition for this library? #51

Open
railsstudent opened this issue Feb 15, 2019 · 4 comments
Open

TypeDefinition for this library? #51

railsstudent opened this issue Feb 15, 2019 · 4 comments

Comments

@railsstudent
Copy link

railsstudent commented Feb 15, 2019

Will lunr-language allow typescript imports to import "lunr-languages/lunr.stemmer.support", "lunr-languages/lunr.multi" and "lunr-languages/lunr.<locale>"?

The workaround is to require(....)(lunr) to add functions to the prototype of lunr and call them in typescript code.

I am not sure how to write the corresponding typedef.d.ts files nor can they be port to typedef files at all.
Please kindly advise.

@crystalfp
Copy link

I have the same problem. Here are few details more from my node.js apprication:

import lunr from "lunr";
require("lunr-languages/lunr.stemmer.support")(lunr);
require("lunr-languages/lunr.multi")(lunr);
require("lunr-languages/lunr.it")(lunr);
const englishItalianSupport = lunr.multiLanguage("en", "it");

Installed lunr types with npm --save-dev @types/lunr but Typescript continue complaining kb.ts:53:36 - error TS2339: Property 'multiLanguage' does not exist on type 'typeof lunr'.

Tried to merge multilanguage() into lunr.Index (just to satisfy the compiler) but without success.

@railsstudent railsstudent changed the title TypeDefinition for TypeScript? TypeDefinition for this library? Feb 21, 2019
@railsstudent
Copy link
Author

I have the same problem. Here are few details more from my node.js apprication:

import lunr from "lunr";
require("lunr-languages/lunr.stemmer.support")(lunr);
require("lunr-languages/lunr.multi")(lunr);
require("lunr-languages/lunr.it")(lunr);
const englishItalianSupport = lunr.multiLanguage("en", "it");

Installed lunr types with npm --save-dev @types/lunr but Typescript continue complaining kb.ts:53:36 - error TS2339: Property 'multiLanguage' does not exist on type 'typeof lunr'.

Tried to merge multilanguage() into lunr.Index (just to satisfy the compiler) but without success.

I encountered the same problem and ended up not using @types/lunr at all.
My solution is
const lunr = require('lunr');
--- the rest of the require codes ----

@ultimaweapon
Copy link

Here is what I use on my project:

// lunr-languages.d.ts
declare module 'lunr-languages/lunr.*' {
  import lunr from 'lunr';

  function register(l: typeof lunr): void;

  export = register;
}
// lunr.d.ts
import { Builder } from 'lunr';

declare module 'lunr' {
  function multiLanguage(...lang: string[]): Builder.Plugin;
}

Put those files in your project's root and it should work automatically.

@crystalfp
Copy link

Fantastic! Thanks @ultimaweapon !

# 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

3 participants