首页 > 其他分享 >[Typescript] 45. Easy - PickValue

[Typescript] 45. Easy - PickValue

时间:2022-10-13 00:11:38浏览次数:52  
标签:Typescript string PickValue 45 street postcode Easy type

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

相关文章

  • TypeScript 诞生 10 周年
    TypeScript诞生10周年来源:OSCHINA编辑: 局2022-10-1008:05:15 7TypeScript已经诞生10年了。10年前——2012年10月1日,TypeScript 首次公......
  • 5 个 TypeScript 库来改进你的代码
    5个TypeScript库来改进你的代码技术爬行之旅2022年09月22日08:57 ·  阅读2060我正在参加「掘金·启航计划」!在过去的几年里,TypeScript 语言除了增长......
  • 中小学教育管理(选修) 00458
    1.课前导入第一章2.3.4.5.6.7.8.9.10.11.......
  • 微信小程序TypeScript网络请求wx.request请求用户自定义返回res.data编译器报错问题
    微信小程序开发,TypeScript,wx.request进行网络请求,返回结果编译器报错,提示有错误:类型“string|Record<string,any>|ArrayBuffer”上不存在属性“error”。类型“str......
  • 代码随想录训练营|Day 22|235,701,450
    235.LowestCommonAncestorofaBinarySearchTreeGivenabinarysearchtree(BST),findthelowestcommonancestor(LCA)nodeoftwogivennodesintheBST.......
  • 用typescript实现一个event bus
    一个简单eventbus的实现发布订阅者模式typeemitKey=number|string|symbol;typefunc=(...args:any)=>void;interfaceBusInterface{emit:(key:emi......
  • 算法竞赛入门【码蹄集新手村600题】(MT1451-1500)
    算法竞赛入门【码蹄集新手村600题】(MT1451-1500)文章目录​​算法竞赛入门【码蹄集新手村600题】(MT1451-1500)​​​​前言​​​​为什么突然想学算法了?​​​​为什么选择......
  • Div 1.455A - Boredom
    思路类似大盗阿福,就是价值变了一下。记得开\(long~long\)(吼)记得开\(long~long\)(吼)记得开\(long~long\)(吼)重要事情说三遍代码#include<iostream>#include<algorit......
  • lhl545-001
    <inputtype="text"onkeyup="value=decimalsFormat(value,20,2)"/***input小数格式*@paramval值*@paramlength总长度*@paramdecimalPlace小......
  • HDU 4245
    ​​HDU-4245​​​​AFamousMusicComposer​​​​Submit​​​ ​​Status​​DescriptionMr.Bisafamousmusiccomposer.Oneofhismos......