Skip to content

Typing for record became too loose after addition of Partial #992

Closed
@hsarokina-ita

Description

@hsarokina-ita

This issue is related to: #751

After updating zod version from v3.12.0 to v3.13.3 we started to receive the following TS error: error TS2322: Type 'Partial<Record<string, string>>' is not assignable to type 'Record<string, string>'. 'string' index signatures are incompatible. Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.

We are using zod record with string keys and values. I think that returning Partial for string records is a bug, because we are sure, that all keys that record has are checked by zod and contain non-undefined value, but TS says that they can contain undefined that forces us to do extra checks in the later code to convince TS that all values are strings.

I've created a repo with simple reproduction to illustrate such use case better:
https://github.com/hsarokina-ita/zod-partial-record
safeParse returned success: false for object with undefined values, this means that zod checked for it to be defined. But at the same time I can assign record with undefined value to typing returned by parser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions