# 9775-大写keys

# 题目描述

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

# 分析

这个题目,其实相比于 1383-Camelize 更为简单。在处理属性上,此题目仅需要大写首字母即可。不再赘述

# 题解

type TupleTranverse<T extends any[]> = T extends [infer F, ...infer R]
  ? F extends Record<string, any>
    ? [CapitalizeNestObjectKeys<F>, ...TupleTranverse<R>]
    : F
  : [];

type CapitalizeNestObjectKeys<T> = {
  [P in keyof T as Capitalize<P & string>]: T[P] extends any[]
    ? TupleTranverse<T[P]>
    : T[P] extends Record<string, any>
    ? CapitalizeNestObjectKeys<T[P]>
    : T[P];
};

# 知识点

  1. 1383-Camelize 麻烦。
Last Updated: 2023/5/16 06:00:28