-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty type inferred by Object.entries #21826
Comments
Looks like this is due to #20553. Previously the second overload of declare function values<T>(x: { [key: string]: T }): T[];
declare function values(x: any): any;
declare function values2<T>(x: { [key: string]: T }): T[];
declare function values2(x: {}): any;
values(a)[0].toUpperCase(); // No error
values2(a)[0].toUpperCase(); // Error This behavior seems sort of strange so I'm wondering if it's intended. |
Talked with @sandersn and it looks like the problem would be fixed if we considered Currently the problem is that when choosing an overload we use a subtype relationship. |
Just jumping in here... I also get a problem with this code: const x: Readonly<{ [id: number]: number }> = { 5: 1 }
const entries = Object.entries(x) It must be
|
I wounder if we should just get back to |
Actually my case was fixed in 2.8-rc but again happening in 2.8.1 . |
Can this issue be expanded so |
So that you know, this is still an issue in 2.9 RC. |
As a work-around, and building on the workaround for export const entries = Object.entries as <T>(
o: T
) => [Extract<keyof T, string>, T[keyof T]][] edit: Looking at it more, I'm not sure |
Can't reproduce this anymore, |
@liamness Shouldn't the TS implementation of |
We still see this issue in TS 3.5 |
|
I think reverting #20553 is the right thing (@saschanaz it still repros for me on master). @DanielRosenwasser do you agree? |
I think so too. It is very similar to how TS handles |
TypeScript Version: 2.7.1
Search Terms: Object entries empty TS2365
Code
Compile command:
tsc --lib es2017,es2017.object a.ts
Expected behavior:
This should compile without any error, assuming
v: any
.This was the case for Typescript 2.6.2 at least.
Actual behavior:
(3,43): error TS2365: Operator '+' cannot be applied to types '{}' and '1'.
Following codes compile without errors:
The text was updated successfully, but these errors were encountered: