TypeScript 声明特定的 SCSS 模块

标签 typescript sass module

我正在尝试声明要从 TypeScript 导入的特定 SCSS 模块。我有这个运行良好的声明文件:

declare module '*.scss' {
  const styles: {
    a: string
    b: string
    c: string
  }

  export default styles
}
但我想缩小 *.scss不知何故,这个声明文件只适用于 SCSS 文件 _variables.scss它位于同一目录中。
我试图替换 *.scss_variables.scss./_variables.scss但后来 TypeScript 根本找不到模块声明。
TypeScript 可以做到这一点吗?

最佳答案

您可以像这样进行模块声明。阅读更多关于通配符模块声明 here .

declare module '*_variables.scss' {
  const styles: {
    a: string
    b: string
    c: string
  }

  export default styles
}

关于TypeScript 声明特定的 SCSS 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64198691/

相关文章:

javascript - 导出调用另一个函数而不是原始函数的新函数有什么意义?

powershell - 函数在模块中使用时没有绑定(bind)

angular - 如何以编程方式将 ionic 按钮添加到 Ionic 导航栏? ( ionic 2、 Angular 2)

javascript - 我可以在 typescript 文件中使用 javascript 吗?

python - 不同模块之间的全局变量

html - 如何否决 SCSS 中的 @extend 指令?

javascript - Angular 2/4/6 : how to update the scss dynamically

javascript - 来自枚举的条件 Typescript 函数类型

TypeScript:接口(interface) vs 类 vs 模块 vs 程序 vs 函数

sass - 当我使用 var 和 rgba 时,CSS 变量在 SCSS 中不起作用