Currently, I am developing a utility function called copyKnownProperties
that is responsible for copying properties from one class or object to another only if the key exists on both objects. In the example provided, you can observe an attempt to copy properties from B
to A
, and this execution is flawless in JavaScript.
I am seeking TypeScript to alert me when there is an attempt to copy properties with mismatched types. As seen in the scenario mentioned, both A
and B
share the same keys, but only the key foo
has consistent type string
across both objects. The implementation of this part is also successful.
The main challenge lies in evading this error by specifying the key within an array named omit
. These keys will be excluded from the copying procedure, thereby eliminating the necessity of warning messages regarding their inconsistent types. However, conveying this information to TypeScript remains uncertain.
In short, my objective is to eliminate the error on line 27 due to the properties specified in the omit
array.