TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: TS: Why isn't union type in object field extracted to out of the object?

3 点作者 acomagu超过 5 年前
I think these type should be equal:<p><pre><code> { a: string | undefined } { a: string } | { a: undefined } </code></pre> These mean same set of values. And if these are equals, the following works:<p><pre><code> Exclude&lt;{ a: string | undefined }, { a: string }&gt; &#x2F;&#x2F; =&gt; { a: undefined } </code></pre> But it don&#x27;t work as I expected. Because { a: string | undefined } is not { a: string } | { a: undefined }.<p>If it works, Exclude&lt;A, B&gt; could be considered as subtraction of set in mathematical context. I think there is big deals if these types are equals. Why not? And please tell me related GitHub issues if you know.

1 comment

valand超过 5 年前
Must be happening for a reason: - Type equivalence is an edge case not covered yet - Type equivalence calculation is too expensive so that compilation time is preferred than type equivalence completeness<p>If you would, please post it in issues, that&#x27;ll be great <a href="https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;TypeScript&#x2F;issues" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;TypeScript&#x2F;issues</a>