Suppose I want to get the contents of a file into a variable like this:

import authWnd from "../../views/authWnd.html!text"; 

In typings added:

 declare module "*!text" { const content: string; export default content; } 

When compiling I get an error:

Error: (2, 21) TS2307: Cannot find the module '../../views/authWnd.html!text'.

I tried to use this plugin for systemJS , set it up like this:

 SystemJS.config({ "defaultJSExtensions": true, map: { css: '/js/system-css.js', text: '/js/text.js' }, meta: { '*.css': { loader: 'css' }, "*.html": { loader: 'text' } }, // .... 

But to sense zero, the same mistake, because The point here is not in this plugin for sure.

Tell me how to import the contents of the file into the variable ts?

UPDATE:

If you do this:

 import authWnd = require("/js/views/authWnd.html!text"); 

In typings:

 declare module "/js/views/authWnd.html!text" { const content: string; export default content; } 

That all works. But why when I do this in typings: declare module "*!text" or declare module "*.html" , I get the error Cannot find module ...

How to solve a problem? Is it even possible?

  • Well, maybe the error is banal in the wrong path to authWnd.html ? - lexxl
  • @lexxl, The path is correct. The fact is that if you do the import like this: import "../../views/authWnd.html!text"; then everything is loaded, in the console in the browser you can see that the file is loaded. But if so: import authWnd from "../../views/authWnd.html!text"; I get a compilation error ts - sanu0074

0