'rename keys from objects if they exist in dictionary (recursively)

(1) I have a simple dictionary as JS object.

const keys = {
  a: 'category',
  b: 'date',
  c: 'days',
} as const;

(2) I have a function which takes input data and renames all keys in found objects of input data. If a key exists in the dictionary relevant value will be used.

const inputDataPassedToFunction = [{ a: 1, b: { c: [2], test: 3 } }] as const;

(3) Expected result

readonly [{
    readonly category: 1;
    readonly date: {
        readonly days: readonly [2];
        readonly test: 3;
    };
}]

(4) Everything works but I have issues with TypeScript typings on line 31 of this file down below.

TS playground: https://tsplay.dev/WvEARm



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source