Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positives on export (destructuring) missing key object with default value #918

Closed
ardok opened this issue Aug 18, 2017 · 3 comments
Closed

Comments

@ardok
Copy link

ardok commented Aug 18, 2017

// constants.js
export const {
  a: {
    // `b` would have been undefined, but we will default the value with a string
    b = 'default value',
  },
} = {
  a: {
    // `b` doesn't exist here
    c: 'test',
  },
};

...

// foo.js
import {b} from './constants';

// And it results in
 error  b not found in './constants'  import/named

It shouldn't throw an error because we have a default value for the key there.

@ardok ardok changed the title False positives on export missing key object with default value False positives on export (destructuring) missing key object with default value Aug 18, 2017
@ljharb
Copy link
Member

ljharb commented Aug 18, 2017

I'm not actually sure how that named export works with destructuring - that seems like something you shouldn't be able to do.

is that exporting just a "b"?

@ardok
Copy link
Author

ardok commented Aug 18, 2017

It's just exporting b.

Code and my app run just fine because it's valid destructuring (with export).
It's just lint complaining about that.

If that's confusing, maybe this is clearer.

// let's say this is an external package called ardo-styles
export default {
  colors: {
    white: '#ffffff',
    black: '#000000',
  },
  padding: {
    small: '8px',
    large: '16px',
  },
};

// ==== Now, this is my project called ArdoFoo ====

// <root>/constants/styles.js
import ArdoStyles from 'ardo-styles';
export const {
  colors: {
    white,
    black,
    // this doesn't exist from ardo-styles, but I just want to put it here.
    // it's cleaner to put it here rather than having another `export const customBlack = '..'`
    customBlack = '#000001',
  }
} = ArdoStyles;

// <root>/components/modal.js
import {white, black, customBlack} from '<root>/constants/styles';
// It shouldn't complain about `customBlack` not being defined

@ljharb
Copy link
Member

ljharb commented May 12, 2021

This appears to be fixed already. Happy to reopen if the current and also next release doesn't solve it.

@ljharb ljharb closed this as completed May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants