Skip to content

Commit f2201d1

Browse files
committed
Adapter type inference fixes
1 parent e04df9b commit f2201d1

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/lib/adapters/arktype.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import type { type } from 'arktype';
22
import {
33
type ValidationAdapter,
44
type RequiredDefaultsOptions,
5-
type Infer,
6-
type InferIn,
75
createAdapter,
86
type ClientValidationAdapter,
97
type ValidationResult,
@@ -21,12 +19,12 @@ const fetchModule = /* @__PURE__ */ memoize(modules);
2119
async function _validate<T extends type.Any>(
2220
schema: T,
2321
data: unknown
24-
): Promise<ValidationResult<Infer<T>>> {
22+
): Promise<ValidationResult<T['infer']>> {
2523
const { type } = await fetchModule();
2624
const result = schema(data);
2725
if (!(result instanceof type.errors)) {
2826
return {
29-
data: result as Infer<T>,
27+
data: result as T['infer'],
3028
success: true
3129
};
3230
}
@@ -42,22 +40,22 @@ async function _validate<T extends type.Any>(
4240

4341
function _arktype<T extends type.Any>(
4442
schema: T,
45-
options: RequiredDefaultsOptions<Infer<T>>
46-
): ValidationAdapter<Infer<T>, InferIn<T>> {
43+
options: RequiredDefaultsOptions<T['infer']>
44+
): ValidationAdapter<T['infer'], T['inferIn']> {
4745
return createAdapter({
4846
superFormValidationLibrary: 'arktype',
4947
defaults: options.defaults,
5048
jsonSchema: createJsonSchema(options),
51-
validate: async (data) => _validate(schema, data)
49+
validate: async (data) => _validate<T>(schema, data)
5250
});
5351
}
5452

5553
function _arktypeClient<T extends type.Any>(
5654
schema: T
57-
): ClientValidationAdapter<Infer<T>, InferIn<T>> {
55+
): ClientValidationAdapter<T['infer'], T['inferIn']> {
5856
return {
5957
superFormValidationLibrary: 'arktype',
60-
validate: async (data) => _validate(schema, data)
58+
validate: async (data) => _validate<T>(schema, data)
6159
};
6260
}
6361

src/lib/adapters/valibot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const valibotToJSONSchema = (options: ToJSONSchemaOptions) => {
4242
return valibotToJSON({ ...defaultOptions, ...options }) as JSONSchema;
4343
};
4444

45-
async function validate<T extends SupportedSchemas>(
45+
async function _validate<T extends SupportedSchemas>(
4646
schema: T,
4747
data: unknown,
4848
config?: Config<GenericIssue<unknown>>
@@ -72,7 +72,7 @@ function _valibot<T extends SupportedSchemas>(
7272
): ValidationAdapter<Infer<T>, InferIn<T>> {
7373
return createAdapter({
7474
superFormValidationLibrary: 'valibot',
75-
validate: async (data) => validate(schema, data, options?.config),
75+
validate: async (data) => _validate<T>(schema, data, options?.config),
7676
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7777
jsonSchema: options?.jsonSchema ?? valibotToJSONSchema({ schema: schema as any, ...options }),
7878
defaults: 'defaults' in options ? options.defaults : undefined
@@ -84,7 +84,7 @@ function _valibotClient<T extends SupportedSchemas>(
8484
): ClientValidationAdapter<Infer<T>, InferIn<T>> {
8585
return {
8686
superFormValidationLibrary: 'valibot',
87-
validate: async (data) => validate(schema, data)
87+
validate: async (data) => _validate<T>(schema, data)
8888
};
8989
}
9090

0 commit comments

Comments
 (0)