Microsoft/TypeScript

Property is not assignable to the same property in generic base type

Open

#61,918 创建于 2025年6月23日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: check: Variance RelationshipsHelp Wanted

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 Search Terms

Property is not assignable to the same property in generic base type

🕗 Version & Regression Information

-This is the behavior in every version I tried, and I reviewed

⏯ Playground Link

https://www.typescriptlang.org/zh/play/?ts=5.8.3#code/IYIwzgLgTsDGEAJYBthjAgSgCwPYIG8AoBBUSGeBABwEsATAc1oDswAeAMQH0BRBAKYAPCAJb0MLAK4BbEAKgAaBDwBSAPgAUIKFLABHKQMgAuFd1UIAPud4BKM2uu2A3EQC+RFGgwAhZFIAZoEKgiJiElh4hCQ0DMxsXHxhouKSsvJK5hraugZGptnOPPaOFsXJscSkpFACEFJQLKQ6eobGEG6knp5AA

💻 Code

abstract class Rho {
  abstract pidgins<F_E extends number, F_J>(brusquest: F_J | F_E): F_J | F_E;
}
class Bluffer extends Rho {
  pidgins<F_E extends number, F_J>(brusquest: F_J | F_E): F_J | F_E 
  {
    return  brusquest;
  }
}

🙁 Actual behavior

Property 'pidgins' in type 'Bluffer' is not assignable to the same property in base type 'Rho'. Type '<F_E extends number, F_J>(brusquest: F_E | F_J) => F_E | F_J' is not assignable to type '<F_E extends number, F_J>(brusquest: F_E | F_J) => F_E | F_J'. Two different types with this name exist, but they are unrelated. Type 'number | F_E | F_J' is not assignable to type 'F_E | F_J'. Type 'number' is not assignable to type 'F_E | F_J'.(2416)

🙂 Expected behavior

No error

Additional information about the issue

The following works with no error:

abstract class Rho {
  abstract pidgins<F_E extends number, F_J>(brusquest: F_J | F_E): F_J | F_E;
  abstract pidgins<F_E extends number, F_J>(brusquest: F_J | F_E): F_J | F_E;
}
class Bluffer extends Rho {
  pidgins<F_E extends number, F_J>(brusquest: F_J | F_E): F_J | F_E 
  {
    return  brusquest;
  }
}

贡献者指南