Closed bfaulk96 closed 1 year ago
Thanks for this MR - it looks really nice. I will try to move forward with next Rambdax version, but it won't happen this month. I will keep you informed as soon as there is a progress.
Thanks for this MR - it looks really nice. I will try to move forward with next Rambdax version, but it won't happen this month. I will keep you informed as soon as there is a progress.
@selfrefactor Awesome, thanks! It's also worth noting – I noticed this with applyDiff
, but I assume this type could also be applied to many other functions to give better type safety/completions 😄
I will close the MR as I fail to see the successful test case.
I receive this error:
Argument of type '({ op: string; path: string; value?: undefined; } | { op: string; path: string; value: number; })[]' is not assignable to parameter of type 'ApplyDiffRule<"a.c" | "a.b" | "a">[]'. Type '{ op: string; path: string; value?: undefined; } | { op: string; path: string; value: number; }' is not assignable to type 'ApplyDiffRule<"a.c" | "a.b" | "a">'. Type '{ op: string; path: string; value?: undefined; }' is not assignable to type 'ApplyDiffRule<"a.c" | "a.b" | "a">'. Type '{ op: string; path: string; value?: undefined; }' is not assignable to type 'ApplyDiffAdd<"a.c" | "a.b" | "a">'. Types of property 'op' are incompatible. Type 'string' is not assignable to type '"add"'.
for this test:
const obj = {a: {b: 1, c: 2}}
const rules = [
{op: 'remove', path: 'a.c'},
{op: 'add', path: 'a.d', value: 4},
{op: 'update', path: 'a.b', value: 2},
]
const result = applyDiff(rules, obj)
If you do manage to provide a passing test, then I will be happy to review it.
I looked into a way we could improve dotwalking types on unknown objects! You can see below how these types work in practice. It's worth noting this relies on Typescript 4.1+