superstruct icon indicating copy to clipboard operation
superstruct copied to clipboard

Error when composing with generics

Open mirryi opened this issue 3 years ago • 2 comments

Hi, thanks for the great library!

Unfortunately, I'm running into some problems when trying to create a schema for a generic type:

import s from "superstruct";

export interface ProviderOptions<C> {
    specific: C;
    // other non-generic properties...
}

export const Schema = <C>(specific: s.Describe<C>): s.Describe<ProviderOptions<C>> => {
    return s.object({
        specific,
        // other non-generic properties...
    });
};

I'm getting this error (when other properties excluded):

Type 'Struct<Simplify<Optionalize<{ specific: C; }>>, { specific: Describe<C>; }>' is not assignable to type 'Describe<ProviderOptions<C>>'.
  Types of property 'TYPE' are incompatible.
    Type 'Simplify<Optionalize<{ specific: C; }>>' is not assignable to type 'ProviderOptions<C>'.

There are no errors when I remove the generic property. Am I missing something here?

mirryi avatar May 15 '21 14:05 mirryi

Hmm I’m not sure, but seems like potentially a bug in our typings or a limitation of Typescript we’d need to work around.

ianstormtaylor avatar May 18 '21 13:05 ianstormtaylor

I'm also running into this issue, for what it's worth

Ivo-Evans avatar Mar 14 '24 13:03 Ivo-Evans