Whats going on with these type errors? (Challenge, TSPlayground Included)

No mater how hard I try I can't seem to fix these Typescript errors. Tbh I'm not much of a typescript wizard and I've mostly been guessing at the types, any pointers in the right direction would be greatly appreciated. I seem to fix one error and three more pop up 🤦‍♂️ Playground (Test-cases & example included): https://tsplay.dev/Wzxn2N The aim of the function is to turn an array of objects with a sibling relationship to one with a parent-child relationship. The example input & output in the TSPlayground should make it clearer. Currently the function works, its just the types are strange.
// This
[
{
keyA: objA,
keyB: objB
},
{
keyA: objA,
keyB: objC
},
{
keyA: objA,
keyB: objD
},
]
// To
[
{
...objA,
allKeyBs: [objB, objC, objD]
}
]
// This
[
{
keyA: objA,
keyB: objB
},
{
keyA: objA,
keyB: objC
},
{
keyA: objA,
keyB: objD
},
]
// To
[
{
...objA,
allKeyBs: [objB, objC, objD]
}
]
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
6 Replies
whatplan
whatplan2y ago
im taking a look rn
whatplan
whatplan2y ago
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
whatplan
whatplan2y ago
got to a solution im decently happy with hopefully it makes sense to you made it much better
whatplan
whatplan2y ago
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
whatplan
whatplan2y ago
its beautiful im actually quite proud that was pretty fun
IceAge2OnDVD
IceAge2OnDVDOP2y ago
Wow that is a nice solution its a fun challenge shame that i don't even really need this bc I just discovered that my database ORM can do this me 🤦‍♂️ cool learning expereince for me though
Want results from more Discord servers?
Add your server