TypeDefinition for this library?
railsstudent opened this issue · 4 comments
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.
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 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 complainingkb.ts:53:36 - error TS2339: Property 'multiLanguage' does not exist on type 'typeof lunr'.
Tried to merge
multilanguage()
intolunr.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 ----
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.
Fantastic! Thanks @ultimaweapon !