所以我有一个用相同名称声明的类和接口。
declare module "mongoose"
{
class Schema<T = any>
{
constructor(definition?: SchemaDefinition);
}
interface Schema<T = any>
{
new(definition?: TypedSchemaDefinition<T>): Schema<T>;
}
}
让我们假设TypedSchemaDefinition
只是将类型参数prop转换为其运行时的对应对象。除非需要,否则为了简单起见,我不会包括实现该功能的所有代码。
道具示例:编译类型=>运行时类型和字符串=>字符串和数字=>数字等...
这不应引发错误。
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
我不知道这是bug还是预期功能,因为mixins和声明合并应该合并两个构造函数类型,并允许ShippingRuntimeType
作为函数的有效参数。如果这是一个错误,那么可以解决吗?
答案 0 :(得分:0)
只需删除.vs文件并将其添加到类型根目录中即可修复打字稿模块IntelliSense。