From d870407a020f9518fbae662f9f48a9aba005a3e2 Mon Sep 17 00:00:00 2001 From: Mathieu Laurent Date: Mon, 31 Jul 2023 03:49:55 +0200 Subject: [PATCH] docs: fix incomplete Records example (#2579) --- README.md | 6 ++++++ README_ZH.md | 6 ++++++ deno/lib/README.md | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 45c87dfb0..bf4868698 100644 --- a/README.md +++ b/README.md @@ -1525,6 +1525,12 @@ type NumberCache = z.infer; This is particularly useful for storing or caching items by ID. ```ts +const userSchema = z.object({ name: z.string() }); +const userStoreSchema = z.record(userSchema); + +type UserStore = z.infer; +// => type UserStore = { [ x: string ]: { name: string } } + const userStore: UserStore = {}; userStore["77d2586b-9e8e-4ecf-8b21-ea7e0530eadd"] = { diff --git a/README_ZH.md b/README_ZH.md index ef86a460d..6ca66463d 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -845,6 +845,12 @@ type NumberCache = z.infer; 这对于按 ID 存储或缓存项目特别有用。 ```ts +const userSchema = z.object({ name: z.string() }); +const userStoreSchema = z.record(userSchema); + +type UserStore = z.infer; +// => type UserStore = { [ x: string ]: { name: string } } + const userStore: UserStore = {}; userStore["77d2586b-9e8e-4ecf-8b21-ea7e0530eadd"] = { diff --git a/deno/lib/README.md b/deno/lib/README.md index a32bb3da8..a561e8a52 100644 --- a/deno/lib/README.md +++ b/deno/lib/README.md @@ -1524,6 +1524,12 @@ type NumberCache = z.infer; This is particularly useful for storing or caching items by ID. ```ts +const userSchema = z.object({ name: z.string() }); +const userStoreSchema = z.record(userSchema); + +type UserStore = z.infer; +// => type UserStore = { [ x: string ]: { name: string } } + const userStore: UserStore = {}; userStore["77d2586b-9e8e-4ecf-8b21-ea7e0530eadd"] = {