Creating Generic Schema Types for Struct Decorators in TypeScript

Has any had any luck creating generic schema types for decorators and such?
I might be off here, but neither of these types:
type AnyStructSchema = S.Schema<Record<PropertyKey, unknown>, any, never>;
type AnyStructSchema = S.Struct<Record<string, unknown>>;


Accept this schema:
S.Struct({
  page: S.NumberFromString,
  limit: S.NumberFromString,
})


I keep getting these errors with or without exactOptionalPropertyTypes enabled 😦
Type 'Struct<{ page: typeof NumberFromString; limit: typeof NumberFromString; }>' is not assignable to type 'Schema<Record<PropertyKey, unknown>, any, never>'.
  Types of property 'annotations' are incompatible.
    Type '(annotations: Schema<{ readonly page: number; readonly limit: number; }, readonly []>) => Struct<{ page: typeof NumberFromString; limit: typeof NumberFromString; }>' is not assignable to type '(annotations: Schema<Record<PropertyKey, unknown>, readonly []>) => Schema<Record<PropertyKey, unknown>, any, never>'.
      Types of parameters 'annotations' and 'annotations' are incompatible.
        Type 'Schema<Record<PropertyKey, unknown>, readonly []>' is not assignable to type 'Schema<{ readonly page: number; readonly limit: number; }, readonly []>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
          The types returned by 'arbitrary(...)' are incompatible between these types.
            Type 'LazyArbitrary<Record<PropertyKey, unknown>>' is not assignable to type 'LazyArbitrary<{ readonly page: number; readonly limit: number; }>'.
              Type 'Record<PropertyKey, unknown>' is missing the following properties from type '{ readonly page: number; readonly limit: number; }': page, limit


The goal here is quite simple - have a function work with only Struct schemas, like so:
// 👍
oof({
  search: S.Struct({
    page: S.NumberFromString,
    limit: S.NumberFromString,
  })
})

// 👎
oof({
  search: S.Number
})
Was this page helpful?