Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何导入和使用存储在自动生成的*.d.ts文件中的typescript接口?_Reactjs_Typescript_Typescript Typings - Fatal编程技术网

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

Reactjs 如何导入和使用存储在自动生成的*.d.ts文件中的typescript接口?,reactjs,typescript,typescript-typings,Reactjs,Typescript,Typescript Typings,在React应用程序中,我得到了以下结构: 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包含以下内容: in

在React应用程序中,我得到了以下结构:

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
中,我想导入
接口
并在函数中使用它,如下所示:

import styles from './MyComponent.module.css'
import { cssExports } from './MyComponent.module.css.d'

const myFunc = (style: cssExports): string => {...}
我收到错误信息:

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


我哪里做错了?

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

"esModuleInterop": true 
也可以像下面一样导出接口

//MyComponent.module.css


谢谢,
esModuleInterop
已经是
true
MyComponent.module.css.d.ts
css模块类型脚本加载程序生成。如果我可以编辑它,直接在接口上添加导出而不是默认导出,我可能可以通过以下方式解决导入接口的问题:
import style,{cssExports}from./MyComponent.module.css'
,但我无法-(
export interface CssExports {
  'myCssClass01': string;
  'myCssClass02': string;
}