Let's consider an interface presented below:
interface User {
id: string;
name: string;
age: number;
}
We also have a method defined as follows:
function getUserValues(properties:string[]):void {
Ajax.fetch("user", properties).then((user:User) => alert(user));
}
An example of a correct call would be:
getUserValues("id", "name", "age");
However, using invalid property names like this will result in an error:
getUserValues("bogus", "stuff", "what_even_am_i_doing");
My goal is to ensure that the properties
array only contains valid property names from the User
interface. Is there a way to achieve this? I'm seeking a solution to maintain safety in this context.