import/no-named-as-default-member
Disallow reading a property of a default import that is also a named export of the module
Also called import-x/no-named-as-default-member
After import config from "./config", config.load is a property of the default export. It isn't the module's named export load. If the default export doesn't have that property, you get undefined. If it does, a named import says the same thing more directly and lets bundlers drop the exports you don't use.
The rule reads the imported module and reports config.load and const { load } = config if the module has a named export load.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"import/no-named-as-default-member" = "error" # or "warn"Examples#
Reported:
config.js
export function load(path) {
return JSON.parse(read(path));
}
export default { port: 3000 };example.js2 problems
import config from "./config";
config.loadCaution: config also has a named export load. Check if you meant to write import {load} from './config' instead.("./app.json");
const { loadCaution: config also has a named export load. Check if you meant to write import {load} from './config' instead. } = config;Not reported:
config.js
export function load(path) {
return JSON.parse(read(path));
}
export default { port: 3000 };example.jsNo problems
import config, { load } from "./config";
load("./app.json");
listen(config.port);