【问题标题】:Typescript Mixins not working as intended in the compilerTypescript Mixins 在编译器中无法按预期工作
【发布时间】:2020-05-01 17:47:59
【问题描述】:

所以我声明了一个同名的类和接口。

declare module "mongoose"
{
  class Schema<T = any>
  {
    constructor(definition?: SchemaDefinition);
  }
  interface Schema<T = any>
  {
    new(definition?: TypedSchemaDefinition<T>): Schema<T>;
  }
}

假设TypedSchemaDefinition 只是将类型参数道具转换为它们的运行时对应物。为了简单起见,我不会包含所有实现此功能的代码,除非需要。

示例道具:编译类型 => 运行时类型 & 字符串 => 字符串 & 数字 => 数字等...

这不应引发错误。

interface ShippingCompileType {
 days: number,
 price: number,
}
const ShippingRuntimeType: TypedSchemaDefinition<ShippingCompileType> = {
  days: Number,
  price: Number,
}
const ShippingSchema = new Schema(ShippingRuntimeType);

Error: TypedSchemaDefinition<ShippingCompileType> is not assignable to SchemaDefinition

我不知道这是错误还是预期的功能,因为 mixins 和声明合并应该合并两个构造函数类型并允许 ShippingRuntimeType 作为函数的有效参数。如果这是一个错误,那么有解决方法吗??

【问题讨论】:

    标签: typescript mongoose declaration mongoose-schema mixins


    【解决方案1】:

    只需删除 .vs 文件并将该文件添加到类型根目录中即可修复 typescript 模块 IntelliSense。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-16
      • 1970-01-01
      • 2019-06-26
      • 2022-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多