0

I have a function called getEntries.

function getEntries(config = defaultConfig, contentTypeFilter = defaultContentTypes) {
      // defaultContentTypes is an Array
}

I'd like getEntries to be called without passing an array literal.

getEntries(config, 'blogPosts', 'pages');

Internally, I would still like to treat it as an array using the rest operator:

function getEntries(config = defaultConfig, ...contentTypeFilter = defaultContentTypes)

But I'm getting an error pointing to the = sign presumably because of the way I'm trying to combine them or because they can't be combined:

Module build failed: SyntaxError: Unexpected token, expected )

I'm aware that I can set a default internally using the OR operator. But I'm curious if combining these two is possible.

reneruiz
  • 2,436
  • 2
  • 20
  • 18
  • You can't use rest with default. – rie May 04 '17 at 20:08
  • A rest parameter will always evaluate to an array (empty if no arguments available). But it will always provide a value, a default initialiser would never run. – Bergi May 04 '17 at 20:14
  • You can add in function something like `let [x=defaultContentTypes[0],y=defaultContentTypes[1]] = contentTypeFilter;` to set default values on rest data. – rie May 04 '17 at 20:17

0 Answers0