[Typescript Challenges] 145 Medium - Public Type

Remove the key starting with _ from given type T.

/* _____________ Your Code Here _____________ */

type PublicType<T extends object> = {
  [Key in keyof T as Key extends `_${string}` ? never: Key]: T[Key]
}

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

type cases = [
  Expect<Equal<PublicType<{ a: number }>, { a: number }>>,
  Expect<Equal<PublicType<{ _b: string | bigint }>, {}>>,
  Expect<Equal<PublicType<{ readonly c?: number }>, { readonly c?: number }>>,
  Expect<Equal<PublicType<{ d: string; _e: string }>, { d: string }>>,
  Expect<Equal<PublicType<{ _f: () => bigint[] }>, {}>>,
  Expect<Equal<PublicType<{ g: '_g' }>, { g: '_g' }>>,
  Expect<Equal<PublicType<{ __h: number; i: unknown }>, { i: unknown }>>,
]

 

posted @   Zhentiw  阅读(2)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2022-07-17 [System Design] Availability
2020-07-17 [ML L9] Clustering (K-MEANS)
2018-07-17 [Vue-rx] Stream an API using RxJS into a Vue.js Template
2018-07-17 [Vue-rx] Access Events from Vue.js Templates as RxJS Streams with domStreams
2018-07-17 [RxJS] Get current value out of Subject (BehaviorSubject)
点击右上角即可分享
微信分享提示