You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When callign Object.values on a partial record with an explicit literal string key set it does not return a union with undefined as expected. This improper type inference can lead to runtime errors by accessing undefined properties.
🔎 Search Terms
"Object.values Partial"
🕗 Version & Regression Information
This changed between versions 4.2.3 and 4.3.5
In the playground, the behavior was correct in version 4.2.3
It first broke in 4.3.5 and still exists in 5.0.4 and nightly.
(I have not tested versions in between 4.2.3 and 4.3.5 as they were not easily available to test in the playground).
/* Incorrect Behavior */typeFoo=Partial<Record<"key",{count: number}>>// Partial Records allow for values to be missing or undefinedconstfoo: Foo={key: undefined}// Value is explicitely set to be undefinedconstvaluesFoo=Object.values(foo)// Type is of {count: number}[]console.log(valuesFoo.map((value)=>value.count))// Runtime error but no type check error/* Correct Behavior */typeBar=Partial<Record<string,{count: number}>>// Record changed to have string primitive insteadconstbar: Bar={key: undefined}// Value is explicitely set to be undefinedconstvaluesBar=Object.values(bar)// Type is of ({count: number} | undefined)[]console.log(valuesBar.map((value)=>value.count))// Error is caught by type checker
🙁 Actual behavior
Object.values did not return a union with undefined. This is incorrect because the return value can be undefined.
🙂 Expected behavior
Object.values should return a union with undefined. This is expected because the return value can be undefined.
The text was updated successfully, but these errors were encountered:
Bug Report
When callign
Object.values
on a partial record with an explicit literal string key set it does not return a union withundefined
as expected. This improper type inference can lead to runtime errors by accessing undefined properties.🔎 Search Terms
"Object.values Partial"
🕗 Version & Regression Information
In the playground, the behavior was correct in version 4.2.3
It first broke in 4.3.5 and still exists in 5.0.4 and nightly.
(I have not tested versions in between 4.2.3 and 4.3.5 as they were not easily available to test in the playground).
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Object.values
did not return a union withundefined
. This is incorrect because the return value can beundefined
.🙂 Expected behavior
Object.values
should return a union withundefined
. This is expected because the return value can beundefined
.The text was updated successfully, but these errors were encountered: