I am trying to integrate/use jsview/jsrender in a typescript project with build done using webpack-4. Since the jsrender/jsviews package installed via npm does not contain type definitions not are they available via DefinitelyTyped but the author(s) of jsview/jsrender have provided the type definitions separately. I saved them in typings/[jsrender, jsview] folders and modified my tsconfig.json as shown below:
My tsconfig.json has the following:
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": ".",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"target": "es2015",
"moduleResolution": "node",
"declaration": false
},
"include": [
"static/js/**/*",
"*/static/ts/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
],
"files": [
"./typings/jsrender/index.d.ts",
"./typings/jsviews/index.d.ts"
]
}
And I import jsrender with:
import * as jsrender from 'jsrender';
And when I try to use jsrender with:
tmpl = jsrender($).templates('Name: {{:name}}');
The webpack complains with the following error:
TS2339: Property 'templates' does not exist on type 'JQuery'.
The first few lines of type definitions for jsrender has the following:
/// <reference types="jquery" />
declare module 'jsrender' {
export = jsrender;
}
declare const jsrender: JQueryStatic;
interface JQueryStatic {
/* var htmlString = $.render.templateName(data, myHelpersObject); // Render named template */
render: {
[tmplName: string]: JsViews.TemplateRender;
};
/* $.views.xxx ... // JsRender/JsViews APIs */
views: JsViews.Views;
/* $.templates(...) or $.templates.templateName: Compile/get template */
templates: JsViews.Templates;
}
I am not sure why does webpack complain even though when debugging, if I just do:
let tmpl = jsrender($);
and put a breakpoint on the line above, I can see that the tmpl object does have the "templates" function available.
I am not sure if it is a webpack issue, tsconfig issue or the way I am using jsrender.