-1

I need to flatten a nested object.

I've got my missingData like this:

{
  a:2,
  b: {
    c:3
  }
}

And I need ...

{
  a:2,
  b:3
}

but my model is like this:

request {
 a: string,
 b: user,
 c: string
}

user {
  id: string
}

I tried this:

let request = missingData;
request.b = request.b.id;

but Type 'string' has no properties in common with type 'user'.

John
  • 1
  • 1
  • 1
    Looks like you need to declare a new type for the shape that you actually want, then assign `{a: missingData.a, b: missingData.b.id}`. – Bergi Aug 07 '23 at 11:06
  • 1
    Welcome to Stack Overflow! Please [edit] the code to be a [mre] that demonstrates your issue without unrelated problems like `number`-vs-`string` or pseudocode type definitions or `id` vs `c`, etc. – jcalz Aug 07 '23 at 13:05

0 Answers0