首页 > 其他分享 >[Typescript] 129. Hard - Capitalize Nest Object Keys

[Typescript] 129. Hard - Capitalize Nest Object Keys

时间:2022-12-06 21:36:33浏览次数:50  
标签:Typescript string _____________ Keys CapitalizeNestObjectKeys Nest extends type 

Capitalize the key of the object, and if the value is an array, iterate through the objects in the array.

 

/* _____________ Your Code Here _____________ */

type CapitalizeNestObjectKeys<T> = T extends any[]
    ? T extends [infer F, ...infer R]
      ? [CapitalizeNestObjectKeys<F>, ...CapitalizeNestObjectKeys<R>]
      : []
    : T extends object
      ? { [K in keyof T as K extends string ? Capitalize<K> : never]: CapitalizeNestObjectKeys<T[K]> }
      : T


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

type foo = {
  foo: string
  bars: [{ foo: string }]
}

type Foo = {
  Foo: string
  Bars: [{
    Foo: string
  }]
}
type cases = [
  Expect<Equal<Foo, CapitalizeNestObjectKeys<foo>>>,
]

 

标签:Typescript,string,_____________,Keys,CapitalizeNestObjectKeys,Nest,extends,type,
From: https://www.cnblogs.com/Answer1215/p/16960609.html

相关文章

  • TypeScript 之 Type
    Type描述:全称叫做'类型别名',为类型字面量提供名称。比Interface支持更丰富的类型系统特性。Type与Interface区别Interface只能描述对象的形状,Type不止Interfa......
  • Nestjs-Authentication 文档翻译
    Authentication认证是大多数应用程序中非常重要的部分.有很多不同的方法和策略去处理认证,根据不同的要求决定。本章节展示了几种不同方式,这些方式通常是能够适用于......
  • TypeScript 4.9 - satisfies 操作符使用方法
    官方版本发布链接https://devblogs.microsoft.com/typescript/announcing-typescript-4-9-beta/#the-satisfies-operator新的satisfies操作符可以验证表达式的类型是否......
  • TypeScript:Type 'boolean' is not assignable to type 'never'.
    问题原因当我们声明一个空数组而不显示键入它并尝试向其中添加元素时,会发生该错误。解决方案声明数组类型即可参考链接https://bobbyhadz.com/blog/typescript-arg......
  • TypeScript 之 Interface
    Interface描述:用来描述对象的形状,能够被继承常用语法(CommonSyntax)1.描述普通对象interfaceJsonResponse{version:number;outOfStock?:boolean;rea......
  • hive和trino中的爆炸函数lateral view explode与cross join unnest用法
    遇到一个不规则的json如下:trace是数组,外面2个time,hash都是单个字段。所以通过hive建表如下,trace使用了array包裹了struct结构:createexternaltablexy_ods.ods_addre......
  • React Warning: validateDOMNesting(...): <div> cannot appear as a descendant of <p>.
    报错信息umi.js:68474Warning:validateDOMNesting(...):<div>cannotappearasadescendantof<p>.其实不难看出是它提示你应该在p标签中写一个select这里造成错误......
  • [Typescript] 127. Hard - Assign
    Youhaveatargetobjectandasourcearrayofobjects.Youneedtocopypropertyfromsourcetotarget,ifithasthesamepropertyasthesource,youshould......
  • 我要涨知识——TypeScript 常见面试题(二)
    又是一个年底来了,好大一批人可能又准备跑路了,最近回家待产话不多说,赶紧开干,给自己整了一个前端面试小助手——微信小程序内搜索“WEB学习学习加油站”,整理了前端经典高频......
  • 详解 Redis 中 big keys 发现和解决
    在使用Redis时,可能会出现请求响应慢、网络卡顿、数据丢失的情况。排查问题的时候,发现是bigkeys的问题。什么是bigkeys在Redis中,一个字符串类型最大可以达到512......