From ca682b0df4a89c96957ac7adbc684900adcc1e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 31 Oct 2025 11:53:26 +0100 Subject: [PATCH 1/3] Fixed inference for generic `Type`s when argument has `Default` property --- ark/type/variants/base.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ark/type/variants/base.ts b/ark/type/variants/base.ts index 95df88bdf2..20deb6e5c1 100644 --- a/ark/type/variants/base.ts +++ b/ark/type/variants/base.ts @@ -637,7 +637,10 @@ interface Type ): reduceOut /** The Type's [StandardSchema](https://github.com/standard-schema/standard-schema) properties */ - "~standard": StandardSchemaV1.ArkTypeProps + "~standard": StandardSchemaV1.ArkTypeProps< + NoInfer, + NoInfer + > // deprecate Function methods so they are deprioritized as suggestions From 18238796b214cfe470b1fc03f5ac9567553b02a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 6 Nov 2025 23:31:50 +0100 Subject: [PATCH 2/3] add tests --- ark/type/__tests__/realWorld.test.ts | 34 +++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/ark/type/__tests__/realWorld.test.ts b/ark/type/__tests__/realWorld.test.ts index 61c64de3fb..13af24ec9b 100644 --- a/ark/type/__tests__/realWorld.test.ts +++ b/ark/type/__tests__/realWorld.test.ts @@ -4,7 +4,7 @@ import { type ArkErrors, type StandardSchemaV1 } from "@ark/schema" -import { scope, type, type Module } from "arktype" +import { scope, type, type Module, type Type } from "arktype" import type { Out, To } from "arktype/internal/attributes.ts" declare class TimeStub { @@ -1366,4 +1366,36 @@ Right: { x: number, y: number, + (undeclared): delete }`) '{ masterItem: true, minPrice: number % 1 & >= 0, qualities: (1 | 2 | 3 | 4 | 5)[] | [null], short: string, skin: string, type: "skin", souvenirAvailable: boolean = false, stattrakAvailable: boolean = false, + (undeclared): reject } | { short: string, skin: string, type: "skin", souvenir: boolean = false, stattrak: boolean = false, quality?: 1 | 2 | 3 | 4 | 5, weight?: number, + (undeclared): reject }' ) }) + + it("allows inferring a schema's type argument in a generic wrapper function when the type uses Default", () => { + function someFunction>( + schema: Type + ): (typeof schema)["infer"] { + const someData = { hello: "world" } + return schema.assert(someData) + } + + const schema = type({ + hello: type("string").pipe(s => s === "world"), + goodbye: "string='blah'" + }) + + someFunction(schema) + }) + + it("allows inferring a schema in a generic wrapper function when the type uses Default", () => { + function someFunction>>( + schema: schema + ) { + const someData = { hello: "world" } + return schema.assert(someData) + } + + const schema = type({ + hello: type("string").pipe(s => s === "world"), + goodbye: "string='blah'" + }) + + someFunction(schema) + }) }) From 3306d446367458e25a462af1a3e71f10006f209f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 7 Nov 2025 10:42:18 +0100 Subject: [PATCH 3/3] use David's trick --- ark/type/variants/base.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ark/type/variants/base.ts b/ark/type/variants/base.ts index 20deb6e5c1..271caec9bb 100644 --- a/ark/type/variants/base.ts +++ b/ark/type/variants/base.ts @@ -638,8 +638,8 @@ interface Type /** The Type's [StandardSchema](https://github.com/standard-schema/standard-schema) properties */ "~standard": StandardSchemaV1.ArkTypeProps< - NoInfer, - NoInfer + this["inferIn"] extends infer _ ? _ : never, + this["inferOut"] extends infer _ ? _ : never > // deprecate Function methods so they are deprioritized as suggestions