codejump
HardPro challengeTypeScript

Deep Readonly (TypeScript)

TypeScriptTypesUtility Types

Implement the DeepReadonly<T> utility type that recursively makes every
property (and nested property) of an object type readonly.

Then implement solve(obj) which accepts a DeepReadonly<Config> object
and returns the configuration summary string.

Type requirements

  • Primitives stay as-is.
  • Arrays become ReadonlyArray<DeepReadonly<Item>>.
  • Tuples preserve their positions and become readonly.
  • Objects get readonly on every property, recursively.
  • Functions are left untouched.

The checker verifies both the runtime output of solve and compile-time
type equality for nested objects, arrays, tuples, optional properties and functions.
Identity types, shallow Readonly and any do not pass these type checks.
This exercise must be submitted in TypeScript.

Sample tests

Test #1Standard config object
Input: [{"db":{"name":"mydb","replicas":["r1","r2"]},"host":"localhost","port":5432}]
Output: "localhost:5432/mydb(2)"
Test #2No replicas
Input: [{"db":{"name":"appdb","replicas":[]},"host":"prod.db","port":3306}]
Output: "prod.db:3306/appdb(0)"
Test #3Three replicas
Input: [{"db":{"name":"mongo","replicas":["a","b","c"]},"host":"10.0.0.1","port":27017}]
Output: "10.0.0.1:27017/mongo(3)"
Test #4Minimal values
Input: [{"db":{"name":"y","replicas":["r"]},"host":"x","port":0}]
Output: "x:0/y(1)"
Test #5Five replicas
Input: [{"db":{"name":"prod","replicas":["r1","r2","r3","r4","r5"]},"host":"a.b.c","port":65535}]
Output: "a.b.c:65535/prod(5)"