我在努力了解TypeScript错误以及如何解决它。
/**
Interface 'AlternativesSchema<N>' incorrectly extends interface 'AnySchema<any>'.
The types returned by 'when(...)' are incompatible between these types.
Type 'this extends AlternativesSchema<infer O> ? O extends Box<infer oT, infer oR> ? AlternativesSchema<BoxType<O, any>> : AlternativesSchema<Box<any, false>> : AlternativesSchema<...>' is not assignable to type 'this'.
Type 'AlternativesSchema<Box<any, false>>' is not assignable to type 'this'.
Type 'N extends Box<infer oT, infer oR> ? AlternativesSchema<BoxType<N, any>> : AlternativesSchema<Box<any, false>>' is not assignable to type 'this'.
Type 'AlternativesSchema<Box<any, false>> | AlternativesSchema<BoxType<N, any>>' is not assignable to type 'this'.
Type 'AlternativesSchema<Box<any, false>>' is not assignable to type 'this'.ts(2430)
*/
export interface AlternativesSchema<N = any> extends Joi.AnySchema {
try<T extends mappedSchema[]>(
...values: T
): this extends AlternativesSchema<infer O>
? (O extends Box<infer oT, infer oR>
? AlternativesSchema<BoxType<O, oT | extractType<T>>>
: AlternativesSchema<Box<extractType<T>, false>>)
: AlternativesSchema<Box<extractType<T>, false>>;
try<T extends mappedSchema[]>(
values: T
): this extends AlternativesSchema<infer O>
? (O extends Box<infer oT, infer oR>
? AlternativesSchema<BoxType<O, oT | extractType<T>>>
: AlternativesSchema<Box<extractType<T>, false>>)
: AlternativesSchema<Box<extractType<T>, false>>;
try(...types: Joi.SchemaLike[]): this;
try(types: Joi.SchemaLike[]): this;
required(): AlternativesSchema<BoxReq<N, true>>;
required(): this;
exist(): AlternativesSchema<BoxReq<N, true>>;
exist(): this;
optional(): AlternativesSchema<BoxReq<N, false>>;
optional(): this;
when<
R,
T1 extends mappedSchema,
T2 extends mappedSchema,
T extends { then: T1; otherwise: T2 }
>(
ref: R,
defs: T
): this extends AlternativesSchema<infer O>
? (O extends Box<infer oT, infer oR>
? AlternativesSchema<
BoxType<O, oT | extractType<T['then']> | extractType<T['otherwise']>>
>
: AlternativesSchema<Box<extractType<T['then']> | extractType<T['otherwise']>, false>>)
: AlternativesSchema<Box<extractType<T['then']> | extractType<T['otherwise']>, false>>;
}