如何导入和使用存储在自动生成的* .d.ts文件中的Typescript接口?

时间:2019-10-02 14:02:48

标签: reactjs typescript typescript-typings

在React应用程序中,我具有以下结构:

@Entity
@Table(name = "lazy_child")
public class LazyChild {
    [...]  

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "file_id")
    private File file;
}

src/Components/MyComponent ├── MyComponent.module.css // Css modules styles ├── MyComponent.module.css.d.ts // Autogenerated style type definition └── MyComponent.tsx // The React component 包含以下内容:

Component.module.css.d.ts

interface CssExports { 'myCssClass01': string; 'myCssClass02': string; } declare const cssExports: CssExports; export = cssExports; 中,我想导入MyComponent.tsx并将其用于函数中,如下所示:

interface

我收到错误消息:

  

模块'“ /src/components/MyComponent/MyComponent.module.css”'没有导出的成员'cssExports'.ts(2305)

我在哪里做错了?

1 个答案:

答案 0 :(得分:0)

看起来您正在使用commonjs模块语法,能否在tsconfig.json中启用此标志并重试

"esModuleInterop": true 

也如下所示的导出界面

// MyComponent.module.css

export interface CssExports {
  'myCssClass01': string;
  'myCssClass02': string;
}