no-named-as-default-member
Added in v0.9.4Configuration
Rule Details
Warns when a property accessed on a default import has the same name as a named export of that module. Named exports are not automatically properties of the default export.
This rule is enabled as a warning in importPlugin.configs.recommended.
Given this module:
Examples of incorrect code for this rule:
Examples of correct code for this rule:
The rule checks names declared directly by the imported module, including local
export lists and namespace aliases. Names reached through export { name } from
or export * from are not checked. Unresolved, ignored and CommonJS-only modules
are skipped.
Like upstream, matching uses identifier names: fruit[pear] is checked, while
fruit['pear'] is not. A shadowed variable named fruit is also checked. The
property default is always allowed. Only default import specifiers are checked;
import { default as fruit } is not.
Options
This rule has no options. It does not provide automatic fixes or suggestions.
Differences from upstream
- Checking imports requires access to the imported files. If you disable both
languageOptions.parserOptions.projectandprojectService, include imported files in the lint targets too. For example, checkingapp.tsalone will not warn aboutfruit.pearfrom an unselectedfruit.ts. Keep either project option enabled to check dependencies automatically. - Imported-file syntax errors are not reported here. If an imported file
contains
export default {}; export const foo = ;, upstream reports a parse error. This rule skips that file without warning aboutobj.foo. Check that file separately for syntax errors. - TypeScript imports work without configuring an ESLint parser. For example,
named exports from
fruit.tsare checked without animport/parserssetting. An explicitimport/extensionslist still restricts which files are checked; extensions listed underimport/parsersare also allowed. - TypeScript's default interop settings apply. With
module: 'nodenext', rslint can warn aboutobj.foowhen a library exposesfoothrough anexport as namespacedeclaration. Upstream only checks those members whenesModuleInterop: trueis set explicitly. SetesModuleInterop: falseto disable this behavior in both tools.