0

I am tying to construct an object literal with two keys coming from a function

const someFunc = () => {foo: "hi", bar: "bye" }
const x = {
   a: "hello",
   b: "world",
   ...someFunc()
}

I am trying to figure out a one liner where i can set the alias of foo and bar to c and d.

Help appreciated. I am using TS

Raheel
  • 7,354
  • 5
  • 40
  • 79
  • Why does it need to fit on one line? TypeScript's going to render your code differently after transpilation anyway. – Heretic Monkey Jan 15 '21 at 17:56
  • because this piece of code is in arrow function in a format `() => ({...some thing happing here..})` – Raheel Jan 15 '21 at 17:57
  • 5
    ... which could easily be rewritten as `() => { /* do something over more than one line */ return { ... }; };` Aim for readability, not cleverness. My advice, freely ignorable. :) – Heretic Monkey Jan 15 '21 at 17:59
  • 3
    `...(({ foo: c, bar: d }) =>({ c, d }))(someFunc())` - but please don't – mbdavis Jan 15 '21 at 18:06
  • 1
    Note that `someFunc()` as written is a syntax error; if you want to return an object literal you need to wrap it in parentheses. Please try to make sure that code in questions constitutes a [mcve]. Good luck! – jcalz Jan 15 '21 at 19:32

0 Answers0