【问题标题】:Declare a universally importable module in TypeScript by an alias通过别名在 TypeScript 中声明一个通用可导入模块
【发布时间】:2019-12-18 23:46:36
【问题描述】:

全部,

我有一个文件

// ./theme/theme.ts
export const theme = {}

现在所有的 React 组件都必须通过相对路径来解析这个模块

import {theme} from '../theme/theme'
// or
import {theme} from '../../theme/theme'

有没有办法避免这种情况,简单地说:

declare module theme {
  export const theme = myTheme
}

我尝试修改tsconfig.json的baseUrl和path属性无济于事

【问题讨论】:

    标签: reactjs typescript create-react-app


    【解决方案1】:

    如果你的问题和我理解的一样,请参考这个post

    同时,使用别名仍将遵循路径声明语法,即

    import {...} from 'aliasSample/moduleSample'
    

    如果我不符合问题内容,​​请尝试写一个解释性评论,因此我可以编辑我的答案

    【讨论】:

      猜你喜欢
      • 2021-07-28
      • 2021-11-04
      • 2021-06-04
      • 2019-02-21
      • 2013-04-12
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多