简体   繁体   English

当您想更改默认导入的名称时,如何修复 import/no-named-as-default ESlint 规则?

[英]How to fix import/no-named-as-default ESlint rule when you want to change the name of a default import?

I have the following warning from ESlint import plugin:我收到来自 ESlint 导入插件的以下警告:

eslint - import/no-named-as-default: use default import syntax to import clearRegister. eslint - import/no-named-as-default:使用默认导入语法导入 clearRegister。

import { default as clearRegister } from "./utils/form/clearForm";

Here I am using default as to rename my default imported function to clearRegister.这里我使用default as将我的默认导入 function 重命名为 clearRegister。 This renaming works as a charm.这种重命名很有魅力。

//clearForm.js
export default function clearForm() {
 ...
}

How can I fix this warning?我该如何解决这个警告?

when you export in default, you can import it with whatever you want for example当您默认导出时,您可以使用任何您想要的方式导入它,例如

import blah from "./utils/form/clearForm";
// Invalid
import { default as clearRegister } from "./utils/form/clearForm";

// Valid
import clearFormfrom "./utils/form/clearForm";

Check here: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default.md在这里查看: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default.md

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 意外令牌=导入/未命名为默认eslint错误 - Unexpected token = import/no-named-as-default eslint error ESLint 首选默认导出导入/prefer-default-export - ESLint Prefer default export import/prefer-default-export MaterialUI 的自定义 ESLint 导入规则 - Custom ESLint Import Rule for MaterialUI 我将如何导入这些es6导出? 它们是导出文件还是默认文件? - How would I import these es6 exports? Are they named exports or default? 如何更改 eslint 设置以了解绝对导入? - How to change eslint settings to understand absolute import? 如何修复 Eslint 错误:在我的 React Typescript 项目中,“默认”被限制用作导出名称 - How to fix Eslint error: 'default' is restricted from being used as an exported name in my React Typescript project 不应从默认导出模块导入命名导出“名称”(导入为“包名称”)(仅默认导出很快可用) - Should not import the named export 'name' (imported as 'packageName') from default-exporting module (only default export is available soon) ESLint:在“./TopBar”中找不到 TopBarClass(导入/命名) - ESLint: TopBarClass not found in './TopBar'(import/named) 如何在没有配置文件的情况下修复导入/导出babel-eslint? - How to fix import/export babel-eslint without configuration file? 在 React 中为命名函数获取“import/no-anonymous-default-export”警告 - Getting 'import/no-anonymous-default-export' warning for named functions in React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM