Let's imagine a scenario where
interface Action<T> {
assignAction(key: keyof T, value: any): void;
}
The type T
is defined as
{
users: User[];
accounts: Account[];
}
Now, when using the assignAction
method, if we attempt to pass in accounts
for the key of users
, it will result in an error due to mismatched types:
assignAction('users', accounts)
Determining how to validate the value
parameter becomes challenging as its type depends on the chosen key
.