diff --git a/.changeset/gold-queens-sneeze.md b/.changeset/gold-queens-sneeze.md new file mode 100644 index 0000000..3293139 --- /dev/null +++ b/.changeset/gold-queens-sneeze.md @@ -0,0 +1,5 @@ +--- +"@typeschema/main": patch +--- + +Fix type inference diff --git a/packages/main/src/selector.ts b/packages/main/src/selector.ts index 4365a79..f67c081 100644 --- a/packages/main/src/selector.ts +++ b/packages/main/src/selector.ts @@ -1,15 +1,24 @@ import type {AdapterResolvers} from './adapters'; import type {AdapterResolver} from './resolver'; import type {Kind} from '@sinclair/typebox'; -import type {SchemaFrom} from '@typeschema/core'; +import type {IfDefined, SchemaFrom} from '@typeschema/core'; +type IsTypeboxSchema = [IfDefined] extends [never] + ? false + : TSchema extends {[Kind]: unknown} + ? true + : false; function isTypeboxSchema( schema: SchemaFrom, ): schema is SchemaFrom { return typeof schema === 'object' && Symbol.for('TypeBox.Kind') in schema; } -type ClassValidatorSchema = new (...args: unknown[]) => object; +type IsClassValidatorSchema = TSchema extends new ( + ...args: unknown[] +) => object + ? true + : false; function isClassValidatorSchema( schema: SchemaFrom, ): schema is SchemaFrom { @@ -30,10 +39,10 @@ export type Select = TSchema extends Function ? TSchema extends {assert: unknown} ? 'arktype' - : TSchema extends ClassValidatorSchema + : IsClassValidatorSchema extends true ? 'classValidator' : 'function' - : TSchema extends {[Kind]: unknown} + : IsTypeboxSchema extends true ? 'typebox' : TSchema extends {__isYupSchema__: unknown} ? 'yup'