Object.values and Object.entries return type any when passing an object defined as having number keys #26010
Labels
Design Limitation
Constraints of the existing architecture prevent this from being fixed
TypeScript Version: 3.1.0-dev.20180727
Search Terms: Object.values Object.entries wrong type inference any
Code
Expected behavior: Type of
v
should be(string | null)[]
.Actual behavior: Type of
v
isany[]
.Playground Link: Typescript Playground doesn't support
Object.values()
.Related Issues: #21089
This bug seems to occur due to the type definitions for ObjectConstructor, which used to include the possibility of number keys in their type signatures. I'm not sure exactly why this was changed to
ArrayLike
to resolve the related issue I linked (this is the exact PR), but it breaks the type inference on the results ofObject.values()
andObject.entries()
when passing it a type defined as havingnumber
keys.This type signature used to be
values<T>(o: { [s: string]: T } | { [n: number]: T }): T[]
, and with this older signature, the example code properly types the result ofObject.values()
.The text was updated successfully, but these errors were encountered: