Skip to content

Commit

Permalink
FOOF
Browse files Browse the repository at this point in the history
  • Loading branch information
googol committed Aug 26, 2023
1 parent 5809f96 commit cc9297f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions deno/lib/__tests__/record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ test("type inference", () => {

util.assertEqual<
recordWithEnumKeys,
Record<"Tuna" | "Salmon", string>
Partial<Record<"Tuna" | "Salmon", string>>
>(true);

util.assertEqual<
recordWithLiteralKeys,
Record<"Tuna" | "Salmon", string>
Partial<Record<"Tuna" | "Salmon", string>>
>(true);
});

Expand Down
15 changes: 13 additions & 2 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3332,13 +3332,24 @@ export interface ZodRecordDef<
}

export type KeySchema = ZodType<string | number | symbol, any, any>;
export type RecordType<K extends string | number | symbol, V> = [
string
] extends [K]
? Record<K, V>
: [number] extends [K]
? Record<K, V>
: [symbol] extends [K]
? Record<K, V>
: [K] extends [BRAND<string | number | symbol>]
? Record<K, V>
: Partial<Record<K, V>>;
export class ZodRecord<
Key extends KeySchema = ZodString,
Value extends ZodTypeAny = ZodTypeAny
> extends ZodType<
Record<Key["_output"], Value["_output"]>,
RecordType<Key["_output"], Value["_output"]>,
ZodRecordDef<Key, Value>,
Record<Key["_input"], Value["_input"]>
RecordType<Key["_input"], Value["_input"]>
> {
get keySchema() {
return this._def.keyType;
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ test("type inference", () => {

util.assertEqual<
recordWithEnumKeys,
Record<"Tuna" | "Salmon", string>
Partial<Record<"Tuna" | "Salmon", string>>
>(true);

util.assertEqual<
recordWithLiteralKeys,
Record<"Tuna" | "Salmon", string>
Partial<Record<"Tuna" | "Salmon", string>>
>(true);
});

Expand Down
15 changes: 13 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3332,13 +3332,24 @@ export interface ZodRecordDef<
}

export type KeySchema = ZodType<string | number | symbol, any, any>;
export type RecordType<K extends string | number | symbol, V> = [
string
] extends [K]
? Record<K, V>
: [number] extends [K]
? Record<K, V>
: [symbol] extends [K]
? Record<K, V>
: [K] extends [BRAND<string | number | symbol>]
? Record<K, V>
: Partial<Record<K, V>>;
export class ZodRecord<
Key extends KeySchema = ZodString,
Value extends ZodTypeAny = ZodTypeAny
> extends ZodType<
Record<Key["_output"], Value["_output"]>,
RecordType<Key["_output"], Value["_output"]>,
ZodRecordDef<Key, Value>,
Record<Key["_input"], Value["_input"]>
RecordType<Key["_input"], Value["_input"]>
> {
get keySchema() {
return this._def.keyType;
Expand Down

0 comments on commit cc9297f

Please sign in to comment.