-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Object.values creates variables implicitly typed as any
with no warning, even with noImplicitAny
#49857
Comments
The signature of |
Note that declare const obj : {[key: string]: string} | {[key: string]: number}
const obj2: {[key: string]: string | number} = obj;
for (const v of Object.values(obj2)) {
v.a.b.c = 42; // Error: Property 'a' does not exist on type 'string | number'.
} This made it particularly surprising to me as I used Also, I would argue that |
That's true, I always forget that, because it really shouldn't do that. It should always return |
Ah, thank you for the link, makes perfect sense now, I didn’t realize this type was actually inconsistent. I guess I'll try to avoid |
Bug Report
In some cases,
Object.values
creates variables implicitly typed asany
without any warning, even thoughnoImplicitAny
is set totrue
.🔎 Search Terms
Object.values, any, noImplicitAny
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
v
has typeany
even though I never wroteany
myself and set thenoImplicityAny
option totrue
.🙂 Expected behavior
Ideally
v
should have typestring | number
, but at the very least it should either have typeunknown
or trigger an "implicit any" warning.The text was updated successfully, but these errors were encountered: