Register ts module when not in a parent folder

873 Views Asked by At

I can't quite figure out was what to write in my tsconfig.json to register my *.html module. My file structure is as follows, and I want to move html.d.ts out of the app folder.

root/
├── tsconfig.json
└── src/
    ├── app/
    │   ├── html.d.ts <-- works when placed here
    │   └── test/
    │       ├── test.controller.ts
    │       ├── test.html
    └── typings/
        └── html.d.ts <-- it should be placed here

I tried using paths, typeRoots and include, neither worked :(

{
    // omitted everything else for brevity
    "compilerOptions": {
        "baseUrl": "./",
        "paths": {
            "*.html": [
                "src/typings/"
            ]
        },
        "typeRoots": [
            "./node_modules/@types",
            "./src/typings"
        ]
    },
    "include": [
        "src/app/**/*",
        "src/typings/*"
    ],
}

How do I get typescript to register my html module when placed in the typings folder?

html.d.ts

declare module "*.html" {
    const template: string;
    export default template;
}

usage

import Template from "./template.html"
1

There are 1 best solutions below

4
On

use

{
   "compilerOptions": {
       "typeRoots" : ["./typings"]
   }
}