superstruct
superstruct copied to clipboard
Error when composing with generics
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?
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.
I'm also running into this issue, for what it's worth