TypeScript正在删除我的html导入

TypeScript正在删除我的html导入,typescript,rollupjs,Typescript,Rollupjs,我有 在一个TypeScript文件中,由于我还有 import MyHtml from "./junkhtml.htm"; 在.d.ts文件中。当我在我的项目上运行GulpTypeScript时,我没有得到任何错误,但是导入被完全删除。TS似乎认为我的导入只存在于类型声明空间中,并不表示任何真实的内容。我如何指示ts是的,导入需要保持,以便汇总(或网页包)可以在下游处理它 这是我的tsconfig.json文件 declare module "*.htm" { const value:

我有

在一个TypeScript文件中,由于我还有

import MyHtml from "./junkhtml.htm";
.d.ts
文件中。当我在我的项目上运行GulpTypeScript时,我没有得到任何错误,但是导入被完全删除。TS似乎认为我的导入只存在于类型声明空间中,并不表示任何真实的内容。我如何指示ts是的,导入需要保持,以便汇总(或网页包)可以在下游处理它


这是我的tsconfig.json文件

declare module "*.htm" {
  const value: string;
  export default value;
}
这是我正在使用的gulpfile

{
  "compilerOptions": {
    "allowUnreachableCode": true,
    "target": "esnext",
    "baseUrl": "./",
    "jsx": "react",
    "allowSyntheticDefaultImports": true,
    "allowJs": true,
    "moduleResolution": "node",
    "module": "esnext",
    "experimentalDecorators": true,
    "lib": ["es2015", "dom"],
    "typeRoots": ["./typings/modules", "./node_modules/@types"]
  },
  "include": ["./**/*.ts", "./**/*.tsx"],
  "exclude": ["node_modules"]
}

TypeScript将在不使用导入声明时删除它们

如果使用导入,则它应在传输后保留在文件中:

const gulp = require("gulp");
const gprint = require("gulp-print").default;
const ts = require("gulp-typescript");
const tsProject = ts.createProject("./tsconfig.json", { noEmitOnError: true });

const dirs = ["applicationRoot", "modules", "util"];

gulp.task("ts", () => {
  var failed = false;
  return gulp
    .src(["./reactStartup.ts", ...dirs.map(f => `./${f}/**/*.ts`), ...dirs.map(f => `./${f}/**/*.tsx`)], { base: "./" })
    .pipe(tsProject())
    .pipe(gprint(filePath => "TypeScript compiled: " + filePath))
    .pipe(gulp.dest(""))
    .on("finish", () => {});
});
import MyHtml from "./junkhtml.htm";

// use it somehow
console.log(MyHtml);

虽然这里不适用,但在其他情况下,有人可能会考虑只考虑副作用,因为这也会在转储后保持导入:

const gulp = require("gulp");
const gprint = require("gulp-print").default;
const ts = require("gulp-typescript");
const tsProject = ts.createProject("./tsconfig.json", { noEmitOnError: true });

const dirs = ["applicationRoot", "modules", "util"];

gulp.task("ts", () => {
  var failed = false;
  return gulp
    .src(["./reactStartup.ts", ...dirs.map(f => `./${f}/**/*.ts`), ...dirs.map(f => `./${f}/**/*.tsx`)], { base: "./" })
    .pipe(tsProject())
    .pipe(gprint(filePath => "TypeScript compiled: " + filePath))
    .pipe(gulp.dest(""))
    .on("finish", () => {});
});
import MyHtml from "./junkhtml.htm";

// use it somehow
console.log(MyHtml);

我不能用一个新项目和问题中包含的文件来重现你的问题。您使用的是什么tsconfig?@TitianCernicova Dragomir-已编辑-请参见上文如何在文件中使用
MyHtml
?就是这样-我没有在变量声明空间中使用它。发布一个答案,我会接受:)