I'm trying to return value from one of model levels. First level works perfectly because type of returning value is T[K] which means ['Login', 'Password', 'Address'] return what i want. But when i change
getProperty(auth, x => x.Address);
to
getProperty(auth, x => x.Address.Address2);
.
I know the 'Address2' property is not directly under the T type.
And i have no idea for what type change 'T[K]' to works also with ie. Address2 property.
Could you help me?
Edit: what's weird getProperty(auth, x => x.Address.Address2.State);
works
export interface Auth {
Login: string;
Password: string;
Address: {
Address2: {
State: string;
}
}
}
let auth: Auth = {
Login: 'login',
Password: 'password',
Address: {
Address2:{
State: 'some state'
}
}
};
function getProperty<T, K extends keyof T>(obj: T, fn: (m: T) => T[K]) {
console.log(fn(obj));
}
getProperty(auth, x => x.Address.Address2);