Skip to content

Commit 1823879

Browse files
committed
add tests
1 parent ca682b0 commit 1823879

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

ark/type/__tests__/realWorld.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
type ArkErrors,
55
type StandardSchemaV1
66
} from "@ark/schema"
7-
import { scope, type, type Module } from "arktype"
7+
import { scope, type, type Module, type Type } from "arktype"
88
import type { Out, To } from "arktype/internal/attributes.ts"
99

1010
declare class TimeStub {
@@ -1366,4 +1366,36 @@ Right: { x: number, y: number, + (undeclared): delete }`)
13661366
'{ 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 }'
13671367
)
13681368
})
1369+
1370+
it("allows inferring a schema's type argument in a generic wrapper function when the type uses Default", () => {
1371+
function someFunction<TSchema extends Record<string, any>>(
1372+
schema: Type<TSchema, {}>
1373+
): (typeof schema)["infer"] {
1374+
const someData = { hello: "world" }
1375+
return schema.assert(someData)
1376+
}
1377+
1378+
const schema = type({
1379+
hello: type("string").pipe(s => s === "world"),
1380+
goodbye: "string='blah'"
1381+
})
1382+
1383+
someFunction(schema)
1384+
})
1385+
1386+
it("allows inferring a schema in a generic wrapper function when the type uses Default", () => {
1387+
function someFunction<schema extends type.Any<Record<string, any>>>(
1388+
schema: schema
1389+
) {
1390+
const someData = { hello: "world" }
1391+
return schema.assert(someData)
1392+
}
1393+
1394+
const schema = type({
1395+
hello: type("string").pipe(s => s === "world"),
1396+
goodbye: "string='blah'"
1397+
})
1398+
1399+
someFunction(schema)
1400+
})
13691401
})

0 commit comments

Comments
 (0)