Skip to content

Feedback on Object.values Changes in v2.8.0 #46

Answered by uhyo
mrsekut asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you for the feedback! This is done intentionally. I know this is inconvenient but I wanted to choose a bit of improved safety.

As a workaround, as you mentioned, you need to manually convert your object to a Record type.

Do note that this is unsafe -- you need to consider cases like this:

type ProductPrices = {
  widget: Price;
  gadget: Price;
};

const obj = {
  widget: { price: 100 },
  gadget: { price: 500 },
  banana: "1万円",
};

// oops!
total(obj);

Actually, assigning ProductPrices to Record<string, Price> has the same unsafety, although TS allows it unfortunately.

The intention of the change is that now you need to do this unsafe operation by yourselves. After all, it is very…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mrsekut
Comment options

Answer selected by mrsekut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants