I am working with two different interfaces:
interface PersonRequirements{
user:string,
password:string,
id:number
}
export interface Requirement<R> {
name: keyof R & string,
save: () => any,/* I want this return type to be same as return type of founded key in R*/
}
Here is an example of how I am using them:
const idRequirement:Requirement<PersonRequirements>={
name:"id",
save:function ():number/* I want this return type to be same as id's return type(number) but in a generic type safe way*/{
//
}
}
I am looking for a way to ensure that the save()
method returns the same data type as the 'id' property, while maintaining type safety. How can I achieve this?