[Typescript] 45. Easy - PickValue
export type PickValue<T extends object, K = keyof T> = K extends keyof T ? T[K] : never;
interface Person {
name: string;
address: {
postcode: string;
street: string;
}
}
const p: Person = {
name: 'Jon',
address: {
postcode: '123',
street: 'abc'
}
}
/*
{
postcode: string;
street: string;
}
*/
type addressType = PickValue<Person, 'address'>
type nameType = PickValue<Person, 'name'>
type notExistType = PickValue<Person, 'notExists'>