Microsoft/TypeScript

Empty types and types with `never` as a key behave differently

Open

#56,691 创建于 2023年12月6日

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

仓库指标

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

描述

🔎 Search Terms

Mapped type unknown

🕗 Version & Regression Information

  • This changed between versions 4.7.4 and 4.8.4

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.0-dev.20231206#code/CYUwxgNghgTiAEYD2A7AzgF3gVwFw5QGsUkB3FAbgCgqMBPABwQEF4BeeAbwG0BpeAJYp4KEADcQMALr4oKOgF8qAemXx1APQD8NVfABySeAFEYMJDCrJ0WKPhTYIEeAB8CoAGZCQwV1wXsONR66vDaumqm5pbWmPAARvaOzm7YKJ7evm6sHNjBaqHhQA

💻 Code

declare const u: unknown;

type A = {[K in never]: any}
//   ^?

// No Error
const a: null | undefined | {} = u;
//    ^?

// Error
const b: null | undefined | A = u;
//    ^?

🙁 Actual behavior

The types a and b appear to be the same, but only the assignment to b causes an error.

🙂 Expected behavior

I'm not sure which is better, I think it's either no error or both errors.

Additional information about the issue

Both were errors in version 4.7.4

贡献者指南