0

With babel, I can make above work well,

import { f as foo } from 'f';

and destructuring assignment feature can make above work well too,

const { a: { b: { c } } } = { a: { b: { c: 10 } } };
console.log(c);  // => return 10

but now I encouter a problem above:

const {
  a: { b: { c } },
  a2: { b: { c } }
} = { a: { b: { c: 10 } }, a2: { b: { c: 90 } } };
console.log(c);  // => return 90, but I also want to get c=10.

If there is any approaches to make a alias like above work?

{
  a: { b: { c as c1 } },
  a2: { b: { c as c2 } }
} = { a: { b: { c: 10 } }, a2: { b: { c: 90 } } };
scott1028
  • 417
  • 2
  • 7
  • 16
  • Import syntax is very different from destructuring syntax, even if their shorthands look superficially similar. – Bergi May 09 '18 at 12:28
  • you can name in the destructuring like normal. `const { a: { b: { c : c1 } } } = { a: { b: { c: 10 } } };` where `c1` is the resulting variable name, but contains the contents of `a.b.c` – rlemon May 09 '18 at 12:33
  • My question is how to make a alias for same property name, not a invalid property name, but the resolution from the topic you mentioned previously is also work for me, thanks very much! – scott1028 May 09 '18 at 12:44

0 Answers0