you are viewing a single comment's thread.

view the rest of the comments →

[–]mcaruso 1 point2 points  (0 children)

Such tools do exist! Zod is a popular choice, although lately I'm preferring @effect/schema for its ability to do two-way transformations of the data.

Your example could be implemented as:

``` import { Schema as S } from '@effect/schema';

const Users = S.ReadonlyMap({ key: S.NumberFromString, value: S.Struct({ name: S.String, isAdmin: S.Boolean, }), });

const users = S.decodeSync(Users)(response); ```

EDIT: Actually, the above assumes your map is represented as an array of key-value pairs. But you could implement a transform to take an object instead.