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'>
标签:Typescript,string,PickValue,45,street,postcode,Easy,type From: https://www.cnblogs.com/Answer1215/p/16786605.html