簡體   English   中英

Typescript Mixins 在編譯器中無法按預期工作

[英]Typescript Mixins not working as intended in the compiler

所以我有一個使用相同名稱聲明的類和接口。

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

假設TypedSchemaDefinition只是將類型參數 props 轉換為其運行時對應物。 除非需要,否則為了簡單起見,我不會包含實現此功能的所有代碼。

示例道具:編譯類型 => 運行時類型和字符串 => 字符串和數字 => 數字等...

這不應該引發錯誤。

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

我不知道這是錯誤還是預期功能,因為混合和聲明合並應該合並兩個構造函數類型並允許ShippingRuntimeType作為函數的有效參數。 如果這是一個錯誤,那么有解決方法嗎?

只需刪除 .vs 文件並將該文件添加到類型根目錄中即可修復打字稿模塊 IntelliSense。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM