-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Empty types and types with never
as a key behave differently
#56691
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
What is that mapped type supposed to do? Regardless, this seems intentional: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-8.html#improved-intersection-reduction-union-compatibility-and-narrowing
|
If the possible assignment of |
I suggest simplifying the example to something like Relevant: #49119 and #49119 (comment) |
Well, it certainly looks like the problem is not that I mapped |
never
as a key behave differently
I suppose the steelmanned version of the issue looks like this export {}
declare const u: unknown;
type Point = { x: number, y: number };
declare function foo<T, K extends keyof T>(obj: T, keys: K[], rest: Omit<T, K> | null | undefined): void;
const p: Point = { x: 0, y: 0 };
// Error, but should OK
foo(p, ["x", "y"], u); |
I'm not committing to take a fix for this since it's pretty niche, but if it's straightforward and doesn't break/slow down something else, we can take a PR |
π Search Terms
Mapped type
unknown
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.4.0-dev.20231206#code/CYUwxgNghgTiAEYD2A7AzgF3gVwFw5QGsUkB3FAbgCgqMBPABwQEF4BeeAbwG0BpeAJYp4KEADcQMALr4oKOgF8qAemXx1APQD8NVfABySeAFEYMJDCrJ0WKPhTYIEeAB8CoAGZCQwV1wXsONR66vDaumqm5pbWmPAARvaOzm7YKJ7evm6sHNjBaqHhQA
π» Code
π Actual behavior
The types
a
andb
appear to be the same, but only the assignment tob
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
The text was updated successfully, but these errors were encountered: