-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b276d71
commit 4d016b7
Showing
5 changed files
with
104 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// @ts-ignore TS6133 | ||
import { expect } from "https://deno.land/x/expect@v0.2.6/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("generics", () => { | ||
async function stripOuter<TData extends z.ZodTypeAny>( | ||
schema: TData, | ||
url: string | ||
): Promise<TData["_output"]> { | ||
const zStrippedResponse = z | ||
.object({ | ||
topLevelKey: schema, | ||
}) | ||
.transform((data) => { | ||
return data.topLevelKey; | ||
}); | ||
|
||
return fetch(url) | ||
.then((response) => response.json()) | ||
.then((data) => zStrippedResponse.parse(data)); | ||
} | ||
|
||
const result = stripOuter(z.number(), ""); | ||
util.assertEqual<typeof result, Promise<number>>(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,2 @@ | ||
import { z } from "./src"; | ||
|
||
async function stripOuter<TData extends z.ZodTypeAny>( | ||
schema: TData, | ||
url: string | ||
): Promise<TData["_output"]> { | ||
const zStrippedResponse = z | ||
.object({ | ||
topLevelKey: schema, | ||
}) | ||
.transform((data) => { | ||
return data.topLevelKey; | ||
}); | ||
|
||
return fetch(url) | ||
.then((response) => response.json()) | ||
.then((data) => zStrippedResponse.parse(data)); | ||
} | ||
|
||
type asdf = Omit<{ a: string }, "b">; | ||
z; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// @ts-ignore TS6133 | ||
import { expect, test } from "@jest/globals"; | ||
|
||
import { util } from "../helpers/util"; | ||
import * as z from "../index"; | ||
|
||
test("generics", () => { | ||
async function stripOuter<TData extends z.ZodTypeAny>( | ||
schema: TData, | ||
url: string | ||
): Promise<TData["_output"]> { | ||
const zStrippedResponse = z | ||
.object({ | ||
topLevelKey: schema, | ||
}) | ||
.transform((data) => { | ||
return data.topLevelKey; | ||
}); | ||
|
||
return fetch(url) | ||
.then((response) => response.json()) | ||
.then((data) => zStrippedResponse.parse(data)); | ||
} | ||
|
||
const result = stripOuter(z.number(), ""); | ||
util.assertEqual<typeof result, Promise<number>>(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters