superstruct
superstruct copied to clipboard
Describe failed on intersection or inheritance
The following two scenario doesn't seem to work when using Describe
. Both of them says
Type 'Struct<{ ... }>' is not assignable to type 'Describe<IMyInterface>'.
Types of property 'TYPE' are incompatible.
// inheritance
interface Child extends Parent { ... };
const childValidator: Describe = object({
...parentValidator.schema,
childField: string(),
});
// intersection
interface Child = Parent & { ... };
const childValidator: Describe = intersection([
parentValidator,
object({
childField: string(),
})
]);
@ianstormtaylor I'm also experiencing this.
The issue seems to arise when using optional properties.
interface Pet {
name: string
owner?: string
}
interface Dog extends Pet {
breed: string
}
const petSchema: s.Describe<Pet> = s.type({
name: s.string(),
owner: s.optional(s.string()),
})
export const dogSchema: s.Describe<Dog> = s.type({
...petSchema.schema,
breed: s.string(),
})
// type error: Types of property TYPE are incompatible
@R-Bower hmm do you know what’s going on? What’s the minimum amount of code that will reproduce it?
Not entirely sure. The example that I included is close to minimal.
You may also need to enable strict mode in your tsconfig. The errors sometimes don't show when strict
is set to false.
@ianstormtaylor hosted a reproduction of the error at https://github.com/R-Bower/superstruct-describe-error-reproduction