Typescript接口...错误地扩展了接口

时间:2020-01-29 23:00:21

标签: typescript

我在努力了解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>>;
  }

0 个答案:

没有答案
相关问题