TypeScript 使用正则表达式声明模块。

4

有没有一种方法可以在TypeScript中一次性声明多个模块?

例如,我该如何简化这段代码:

declare module '*.png' {
    const value: any;
    export = value;
}

declare module '*.jpg' {
    const value: any;
    export = value;
}

declare module '*.gif' {
    const value: any;
    export = value;
}

declare module '*.svg' {
    const value: any;
    export = value;
}
1个回答

0

我认为您不能将正则表达式或通配符作为模块名称使用。但是,如果所有这些图像文件都在一个单独的文件夹中,例如images/,那么您可以执行以下操作:

declare module 'images/*' {
  const value: any;
  export = value;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接