I want to write a function that returns a single property that exists on a type:
type CustomType = {
property1: boolean;
property2: numeric;
};
private getData(obj): CustomType {
// do stuff
return dataObj;
}
private getBooleanValue(obj, key): boolean {
const value = this.getData(obj)[key];
// do stuff
return value;
}
I want to put a restriction on getBooleanValue's key, that the key is part of CustomType - for example:
getBooleanValue(obj, "property1") // OK
getBooleanValue(obj, "property2") // ERROR, TypeScript won't allow this