'subtracting identical object values typescript
I would to know how to subtract identical object values in typescript using Generics and type-safe, based on: subtracting identical object values javascript
const subtractObjects = <T extends Record<String, number>>(objA: T, objB: T): T =>
Object.keys(objA).reduce((a, k) => {
a[k] = objA[k] - objB[k];
return a;
}, {});
I receive the error:
Type '{}' is not assignable to type 'T'.
'{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Record<string, number>'.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
