如何修复ESLINT错误:'默认值'被限制不受我的反应打字条项目中的导出名称
我正在更新我的React项目中的ESLINT规则。
目前,我在扩展
属性中eslintrc.js
:
extends: [
'airbnb',
'airbnb-typescript',
'airbnb/hooks',
// "plugin:@typescript-eslint/recommended",
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
// "plugin:eslint-comments/recommended",
'plugin:react/recommended',
'plugin:jest/recommended',
'plugin:prettier/recommended',
],
我遇到此错误:
错误'默认值'被限制被用作导出名称 无限制的出口
我们对组件的模式是这样的:
Button/
- Button.tsx
- Button.spec.ts
- Button.stories.tsx
- index.ts
index.ts:
从'./button'export {default} export {default};
如何解决这个问题?还是我必须以某种方式覆盖这个Eslint规则?
I am updating eslint rules in my React project.
Currently I have this in the extend
property inside eslintrc.js
:
extends: [
'airbnb',
'airbnb-typescript',
'airbnb/hooks',
// "plugin:@typescript-eslint/recommended",
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
// "plugin:eslint-comments/recommended",
'plugin:react/recommended',
'plugin:jest/recommended',
'plugin:prettier/recommended',
],
I am getting this error:
error 'default' is restricted from being used as an exported name
no-restricted-exports
Our pattern for components is like this:
Button/
- Button.tsx
- Button.spec.ts
- Button.stories.tsx
- index.ts
index.ts:
export { default } from './Button';
How to fix this? Or do I have to override this eslint rule somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要禁用此规则 -
无限制的exports
。您的.eslintrc文件将在这里看起来像这样
的文档 - htttps:htttps:// eslint。 org/doc/最新/规则/无限制的exports 。
另一个选项是不使用默认导出,而是执行这样的操作:
在index.ts文件中:
You'll need to disable this rule -
no-restricted-exports
.Your .eslintrc file will look like this
More documentation here - https://eslint.org/docs/latest/rules/no-restricted-exports.
Another option would be to not use default exports but instead do something like this:
and in the index.ts file: