首页 > 解决方案 > 递归地为对象中的每个键添加后缀

问题描述

功能被最小化。它应该将“blabla”添加到每个对象键作为后缀(递归)。

TS游乐场链接

错误

Type 'any[]' is not assignable to type 'T'.
  'T' could be instantiated with an arbitrary type which could be
    unrelated to 'any[]'.
(2322)

输入

addBlabla([{ a: [{ b: 1 }] }])

输出

{
  ablabla: {
    b: number; // not a "bblabla"
  }[];
}[]

TS游乐场链接

标签: typescript

解决方案


TS 游乐场:https ://tsplay.dev/wQKyVm

我删除Array.isArray了部分,因为 Array 也是对象(typeof)。


推荐阅读