Hypothetically, imagine having an interface structured in the following manner:
interface Cat {
weight: number;
name: string;
adoptable: boolean;
}
The objective is to create a separate interface that serves the purpose of setting values on Cat
:
interface CatUpdate {
field: keyof Cat;
value: ???
}
It is critical for TypeScript to validate that the value corresponds to the appropriate type based on the specified field. For instance, the following scenario should be deemed incorrect:
const x: CatUpdate = {
field: "name",
value: 12
}
The query arises on how to specifically define the type of CatUpdate.value
.