Buckets:
ktongue/docker_container / .opencode /node_modules /zod /src /v4 /classic /tests /instanceof.test.ts
| import { expect, expectTypeOf, test } from "vitest"; | |
| import * as z from "zod/v4"; | |
| test("instanceof", async () => { | |
| class Test {} | |
| class Subtest extends Test {} | |
| abstract class AbstractBar { | |
| constructor(public val: string) {} | |
| } | |
| class Bar extends AbstractBar {} | |
| const TestSchema = z.instanceof(Test); | |
| const SubtestSchema = z.instanceof(Subtest); | |
| const AbstractSchema = z.instanceof(AbstractBar); | |
| const BarSchema = z.instanceof(Bar); | |
| TestSchema.parse(new Test()); | |
| TestSchema.parse(new Subtest()); | |
| SubtestSchema.parse(new Subtest()); | |
| AbstractSchema.parse(new Bar("asdf")); | |
| const bar = BarSchema.parse(new Bar("asdf")); | |
| expect(bar.val).toEqual("asdf"); | |
| await expect(() => SubtestSchema.parse(new Test())).toThrow(); | |
| await expect(() => TestSchema.parse(12)).toThrow(); | |
| expectTypeOf<Test>().toEqualTypeOf<z.infer<typeof TestSchema>>(); | |
| }); | |
| test("instanceof fatal", () => { | |
| const schema = z.instanceof(Date).refine((d) => d.toString()); | |
| const res = schema.safeParse(null); | |
| expect(res.success).toBe(false); | |
| }); | |
Xet Storage Details
- Size:
- 1.05 kB
- Xet hash:
- 42ff29ab53abf0119d790843822d9abb8a1398dc79b65e3fc682152278fbfcad
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.