Microsoft/TypeScript

C extends A but C does not extend A | B

Open

#59,034 创建于 2024年6月26日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
Domain: check: Variance RelationshipsHelp WantedPossible Improvement

仓库指标

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

描述

🔎 Search Terms

union extends

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about unions and extends

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.2#code/C4TwDgpgBAglC8UDeUCGAuKBGANFARpgM7ABOAlgHYDmAvlAD7JqYBMUehUJFNtA3AFgAUKEhQAQgmYYorPAGNiZKtSgCRY6AGFpKWVkZzOy3mo3DN4aAHUA9qQDWRADwAVKBAAewCJQAmRLDS2gB80m5CotZQACJ2EEQAcnbA9k7unj5+gcFMUohhEfxAA

💻 Code

type A = { a: 1, b: string} | { a: 2 , b: string};
type B = { a: 2, c: string };
type C = { a: 1 | 2, b: string };

type Works<T extends A = C> = T;
type DoesNotWork<T extends A | B = C> = T;

🙁 Actual behavior

An error tells that C does not extend A | B

🙂 Expected behavior

No error since C extends A and therefore extends A | B

Additional information about the issue

No response

贡献者指南