Looking to create a data type that represents changes in an object.
For instance:
const test: SomeType = {
a: 1,
b: "foo"
};
const changing1: Changing<SomeType> = {
obj: test,
was: {
a: test.a
},
now: {
a: 3
} // Correct one
const changing2: Changing<SomeType> = {
obj: test,
was: {
a: test.a
},
now: {
b: "bar"
} // Incorrect one
Attempted to accomplish this with the following code:
type Changing<T, K = {[R in keyof T]: T[R]}, P extends K = {[R in keyof K]: K[R]}> = {
obj: T,
was: K,
now: P
}
The initial idea was to constrain P as an extension of K but with the same members. It seems like it doesn't work as expected.