【问题标题】:Wildcard module for importing text not type checking用于导入文本而不是类型检查的通配符模块
【发布时间】:2017-11-26 20:36:52
【问题描述】:

这是通配符模块定义:

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

还有导入:

import * as html from 'text!./myHtml.html';

还有编译器错误:

错误 TS2345:'typeof'text!*'' 类型的参数不可分配给 'string | 类型的参数((这个:HTMLElement,索引:数字, oldhtml: string) => string)'。

我真的希望 html 的类型为 string

【问题讨论】:

    标签: typescript


    【解决方案1】:

    我真的希望 html 具有字符串类型。

    然后,将导出更改为字符串。我在下面显示无效和正确的代码?

    无效

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

    正确

    declare module 'text!*' {
        const content: string;
        export = content;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-02-01
      • 2022-01-08
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 2021-04-02
      • 2020-01-14
      • 2017-04-12
      • 1970-01-01
      相关资源
      最近更新 更多