Skip to content

Commit

Permalink
chore: automatic fixes and code generation for 66cbfe0 (Merge pull re…
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks authored and github-actions[bot] committed Mar 2, 2022
1 parent 66cbfe0 commit 1c0084f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
25 changes: 22 additions & 3 deletions deno/lib/__tests__/record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ const recordWithLiteralKeys = z.record(
type recordWithLiteralKeys = z.infer<typeof recordWithLiteralKeys>;

test("type inference", () => {
const f1: util.AssertEqual<booleanRecord, Record<string, boolean>> = true;
const f1: util.AssertEqual<
booleanRecord,
Partial<Record<string, boolean>>
> = true;
f1;

const f2: util.AssertEqual<
recordWithEnumKeys,
Record<"Tuna" | "Salmon", string>
Partial<Record<"Tuna" | "Salmon", string>>
> = true;
f2;
const f3: util.AssertEqual<
recordWithLiteralKeys,
Record<"Tuna" | "Salmon", string>
Partial<Record<"Tuna" | "Salmon", string>>
> = true;
f3;
});
Expand Down Expand Up @@ -91,6 +94,22 @@ test("key schema", () => {
Salmon: "asdf",
});

// shouldn't require us to specify all props in record
const result3 = recordWithEnumKeys.parse({
Tuna: "abcd",
});
expect(result3).toEqual({
Tuna: "abcd",
});

// shouldn't require us to specify all props in record
const result4 = recordWithLiteralKeys.parse({
Salmon: "abcd",
});
expect(result4).toEqual({
Salmon: "abcd",
});

expect(() =>
recordWithEnumKeys.parse({
Tuna: "asdf",
Expand Down
4 changes: 2 additions & 2 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2367,9 +2367,9 @@ export class ZodRecord<
Key extends KeySchema = ZodString,
Value extends ZodTypeAny = ZodTypeAny
> extends ZodType<
Record<Key["_output"], Value["_output"]>,
Partial<Record<Key["_output"], Value["_output"]>>,
ZodRecordDef<Key, Value>,
Record<Key["_input"], Value["_input"]>
Partial<Record<Key["_input"], Value["_input"]>>
> {
get keySchema() {
return this._def.keyType;
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const recordWithLiteralKeys = z.record(
type recordWithLiteralKeys = z.infer<typeof recordWithLiteralKeys>;

test("type inference", () => {
const f1: util.AssertEqual<booleanRecord, Partial<Record<string, boolean>>> = true;
const f1: util.AssertEqual<
booleanRecord,
Partial<Record<string, boolean>>
> = true;
f1;

const f2: util.AssertEqual<
Expand Down

0 comments on commit 1c0084f

Please sign in to comment.