首页 > 其他分享 >[Typescript] 122. Hard - Mutable Keys

[Typescript] 122. Hard - Mutable Keys

时间:2022-11-30 14:56:44浏览次数:56  
标签:_____________ Keys MutableKeys 122 Expect Key Mutable type

Implement the advanced util type MutableKeys, which picks all the mutable (not readonly) keys into a union.

For example:

type Keys = MutableKeys<{ readonly foo: string; bar: number }>;
// expected to be “bar”
 
/* _____________ Your Code Here _____________ */

type MutableKeys<T> = keyof {
  [Key in keyof T as Equal<Pick<T, Key>, Readonly<Pick<T, Key>>> extends true ? never: Key]: T[Key]
}

/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<MutableKeys<{ a: number; readonly b: string }>, 'a'>>,
  Expect<Equal<MutableKeys<{ a: undefined; readonly b: undefined }>, 'a'>>,
  Expect<Equal<MutableKeys<{ a: undefined; readonly b?: undefined; c: string; d: null }>, 'a' | 'c' | 'd'>>,
  Expect<Equal<MutableKeys<{}>, never>>,
]

 

标签:_____________,Keys,MutableKeys,122,Expect,Key,Mutable,type
From: https://www.cnblogs.com/Answer1215/p/16938445.html

相关文章

  • 29.1227
    #include<stdio.h>intmain(){ inti,j,n,a[50],b[50],k,l,m; scanf("%d",&n); for(i=0;i<n;i++) {scanf("%d%d",&a[i],&b[i]); } for(i=0;i<n;i++) {for(j=1;j<b[......
  • 0122-Go-模板字符串
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/text-templates目标使用Go语言的模板字符串。示例packagemainimport("os""t......
  • Immutable(不可变)集合
    不可变集合,顾名思义就是说集合是不可被修改的。集合的数据项是在创建的时候提供,并且在整个生命周期中都不可改变。为什么要用immutable对象?immutable对象有以下的优点:对不可......
  • [Typescript] 119. Extreme - Get Readonly Keys
    Implementageneric GetReadonlyKeys<T> thatreturnsaunionofthereadonlykeysofanObject.ForexampleinterfaceTodo{readonlytitle:stringreado......
  • [Typescript] 117. Hard - ClassPublicKeys
    Implementthegeneric ClassPublicKeys<T> whichreturnsallpublickeysofaclass.Forexample:classA{publicstr:stringprotectednum:numberpri......
  • D110设计模式_4备忘录模式20221122
     备忘录模式(MementoPattern)保存一个对象的某个状态,以便在适当的时候恢复对象。备忘录模式属于行为型模式。客户不与备忘录类耦合,与备忘录管理类耦合。优点: 1、给用......
  • 【iOS-cocos2d-X 游戏开发之九】Cocos2dx利用CCSAXParser解析xml数据&CCMutableDictio
    本站文章均为​​ 李华明Himi ​​​原创,转载务必在明显处注明本章Himi给大家分享如何在Cocos2dX中解析xml数据;对于数据存取有很多方式,流文件,plist,xml等,那么为了跨平台更......
  • OpenSSL 把cer证书链以及key文件生成keystore,tomcat https配置
    最近接触的项目中用到HTTPS,并且申请了证书以及私钥,这一块接触的少先整理出来,谨防以后忘记。因为是tomcat中配置的https,需要将证书转成keystore文件,通过openssl先通过证......
  • [VS Code] Cannot read keys when either application does not have a console or wh
    在VSCode运行C#Console程序报错。 原因:  解决方案:1.打开launch.json.  2.修改  "console":"internalConsole" --> "console":"integra......
  • GL-Talking about rules 20221122
    TimeTalkingaboutrulesDidyouhavestrictrulestofollowwhenyouwereateenager?Discusswhatguidelinesamodernfamilyshouldfollow?Teenagersshouldn......