no-named-as-default
Added in v0.9.4Configuration
rslint.config.ts
Rule Details
Reports a default import whose local name is also a named export of the imported module. This can indicate a missing pair of braces around a named import.
Given this module:
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Unresolved and ignored modules, modules without a default export, and files using only CommonJS exports are skipped. TypeScript export = assignments available as default imports are also checked. Like upstream v2.32.0, the rule permits a name when both it and the default are explicit re-exports from the same file. Exporting the same local value under both names does not receive this exemption.
Options
This rule has no options. It does not provide automatic fixes or suggestions.
Differences from upstream
- When both
languageOptions.parserOptions.projectandprojectServiceare disabled, only imported files also selected for linting can be checked. For example, lintingapp.tsalone does not check names exported bylib.ts. Enable either project option to check dependencies without linting them directly. - Babel's experimental
export name from './module'syntax is not supported. Useexport { default as name } from './module'instead; this standard syntax is not checked by this rule, matching upstream. - Syntax errors in imported files are not reported by this rule. For example,
importing a file containing
return; export {};produces a parse-error report upstream, but no report from this rule. Check the imported file's syntax separately. - Quoted re-export names can produce reports that upstream misses. For example,
given a module with
export default 1; export { foo as 'foo' } from './base', rslint reportsimport foo from './module'; upstream v2.32.0 does not. Quotingdefaultor the name being re-exported also does not prevent rslint from checking for a name collision. - rslint does not report an import just because its name matches a member of
a re-exported namespace. For example, if
module.jscontainsexport default 1; export * as names from './base', a named exportfooinbase.jsdoes not makeimport foo from './module'an error. Upstream v2.32.0 reports this case. esModuleInteropdoes not supply a missing ES module default. Given onlyexport const foo = 1invalues.mjs, rslint skipsimport foo from './values.mjs'because there is no default-name collision. Enableimport/defaultto report the missing default. WithesModuleInterop: true, upstream v2.32.0 reports a collision instead.- With NodeNext, native ES imports of CommonJS modules receive
module.exportsas their default, regardless ofesModuleInterop. For example, ifvalues.ctsexportsconst foo,import foo from './values.cjs'in an.mtsfile is checked for a name collision even when interop is omitted or disabled. Upstream v2.32.0 requires explicitesModuleInterop: true.